Fast 404s for missing images in WordPress

If you’re looking to replace WordPress’s long load time for a 404 error page for at least the missing images on your website, consider adding the following to the .htaccess file that sits in the root of your WordPress installation airblown inflatables canada:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} \.(gif|jpg|jpeg|png)$
RewriteRule .* /wp-content/themes/your-theme/images/placeholder.png [L]

In practice, this looks something like:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} \.(gif|jpg|jpeg|png)$ 
RewriteRule .* /wp-content/themes/your-theme/images/placeholder.png [L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Working with Nginx? No problem, here’s the equivalent commands that go into your site configuration file:

location ~* (jpg|jpeg|gif|png) {
	expires 30d;
	access_log off;

	error_page 404 /wp-content/themes/your-theme/images/placeholder.png;
}

Leave a Reply

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