Handling WordPress 404 errors for static files

I’m sure you will face the problem, if a css / js / image file not exits on the server.
But you don’t know, the wordpress loads the main page!

You can try, this link loads the main page: http://wordpressvirusremoval.com/blog/not_exist.jpg

So in extreme situation 1 page load = 5 page loads!

Simply modify you .htaccess file:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(robots\.txt|sitemap\.xml(\.gz)?)
RewriteCond %{REQUEST_URI} !\.(css|js|html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ [NC]
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Note: if you website runs from a “dir” like this blog/ be aware these lines:

RewriteBase /blog/
RewriteRule . /blog/index.php [L]

the / needs to be changed to /blog/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.