Skip to content

Instantly share code, notes, and snippets.

@rmpel
Last active March 13, 2023 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmpel/fb2b2883aae22643ad097e326be7b7de to your computer and use it in GitHub Desktop.
Save rmpel/fb2b2883aae22643ad097e326be7b7de to your computer and use it in GitHub Desktop.
Fast image 404 in WordPress
# WordPress will serve a rich 404 page for missing images, in case of lots of images, this will put
# heavy load on the server and the 404 messages cannot be shown anyways
# So just send a light-weight Apache 404 message
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpg|jpeg|png|gif|svg)$ - [R=404,NC,L]
# Alternative version; send a 410 Gone, which is even faster.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpg|jpeg|png|gif|svg)$ - [G]
# Using a local environment? is this a copy of a live site? maybe use the live images then;
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpg|jpeg|png|gif|svg)$ https://your-remote-domain.com%{REQUEST_URI} [L,NC,QSA,R=307]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment