Override wordpress 404 processing for static file types globally
Wordpress shows a custom 404 error page for every 404 error even for static file types like images (.jpg), .css .js etc
I want to override the processing of non-existing static files at a global level so that files like this don't get processed by WordPress but just get a server 404 error response.
I feel this would have a huge benefit to server resource usage.
I tried adding the following to WHM Apache config within the include editor under "Pre VirtualHost Include" but it had no effect. Can anyone assist?
<IfModule rewrite_module>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(robots\.txt|[a-z0-9_\-]*sitemap[a-z0-9_\-]*\.(xml|xsl|html)(\.gz)?)
RewriteCond %{REQUEST_URI} \.(css|htc|less|js|js2|js3|js4|html|htm|rtf|rtx|svg|txt|xsd|xsl|xml|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|webp|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|_ttf|wav|wma|wri|woff|woff2|xla|xls|xlsx|xlt|xlw|zip)$ [NC]
RewriteRule .* - [L]
</IfModule>
-
Hey there! It looks like you pulled that code block from https://wordpress.stackexchange.com/questions/24587/how-do-i-skip-wordpresss-404-handling-and-redirect-all-404-errors-for-static-fi. That may work fine, although we don't create or test custom .htaccess code on our side, but you'll also want to rename or remove any local 404.php files or else they will still likely be used.
Unless your server was getting attached, I can't imagine that serving 404 pages would cause a load on the system.
0
Please sign in to leave a comment.
Comments
1 comment