How to redirect 404 directly on (shared) server?
-
Due to some SPAM issue my site get hammered with requests for now dead links, there where a few 1000 links. So many that it slows down the shared server a lot and makes the site very slow. Every hit triggers a WordPress “page not found”.
I am on a cPanels shared host with Litespeed. The logical way would be to let Apache handle it through some HTACCESS lines and point all 404 to a i.e. 404.html page OUTSIDE of WordPress.
But whatever I do either nothing happens, or all requests go to that 404.html page. Usually nothing happens.
This is my original .htaccess
<IfModule LiteSpeed> RewriteEngine on CacheLookup on RewriteRule .* - [E=Cache-Control:no-autoflush] RewriteRule \.litespeed_conf\.dat - [F,L] RewriteRule wp-content/.*/[^/]*(responsive|css|js|dynamic|loader|fonts)\.php - [E=cache-control:max-age=3600] RewriteRule favicon\.ico$ - [E=cache-control:max-age=86400] CacheKeyModify -qs:fbclid CacheKeyModify -qs:gclid CacheKeyModify -qs:utm* CacheKeyModify -qs:_ga </IfModule> <IfModule mod_rewrite.c> RewriteEngine On RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> <IfModule mime_module> AddHandler application/x-httpd-alt-php74 .php .php7 .phtml </IfModule> <IfModule LiteSpeed> php_value auto_prepend_file '/home/myshared/public_html/wpraw/wordfence-waf.php' </IfModule> <IfModule lsapi_module> php_value auto_prepend_file '/home/myshared/public_html/wpraw/wordfence-waf.php' </IfModule> <Files ".user.ini"> <IfModule mod_authz_core.c> Require all denied </IfModule> <IfModule !mod_authz_core.c> Order deny,allow Deny from all </IfModule> </Files>
What I tried so far:
ErrorDocument 404 /404.html #not sure where to exactly need to place that
and
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /404.html [L]
I have 404 in html, php and shtml, with path, with URL and just text, like:
ErrorDocument 404 "No bots allowed!"
How can I make a server 404 redirect work?
- The topic ‘How to redirect 404 directly on (shared) server?’ is closed to new replies.