Last active
March 13, 2023 09:27
-
-
Save rmpel/fb2b2883aae22643ad097e326be7b7de to your computer and use it in GitHub Desktop.
Fast image 404 in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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