Forum Moderators: phranque
/images/mnt/example1.gif
/images/mnt/example-abc.gif
/images/mnt/abc-example.gif
/images/mnt/11234.gif
etc.
to become:
/images/mnt/errorgif.gif
due to a large number of broken images during a large site change over. There are no images in the /mnt/ folder anymore but I want something to appear rather than broken images. I came up with several versions such as:
RewriteEngine On
RewriteRule ^[^/]+/images/(.+)$ /images/mnt/errorgif.gif [L]
RewriteEngine On
RewriteRule ^/images.* /mnt/errorgif.gif [L]
but nothing works.
Try:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/images/mnt/errorgif\.gif$
RewriteRule [b]^im[/b]ages/mnt/.+\.gif$ /images/mnt/errorgif.gif [L]
Another way to do this is to detect (all) missing images, and rewrite them to "missing.gif". This is not as efficient in use of server CPU-time, but it may be more efficient in use of *your* time.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.gif$ /images/mnt/errorgif.gif [L]
RewriteEngine on
RewriteCond %{REQUEST_URI}!^/images/mnt/errorgif\.gif$
RewriteRule ^images/mnt/.+\.gif$ /images/mnt/errorgif.gif [L]
The final location of the errorgif.gif is:
h**p://www.example.com/images/mnt/errorgif.gif
I've tried placing the above mod_rewrite in /mnt/, /images/ and even the root but it does not seem to have an effect. Which folder should the htaccess file containing this code be in? Also, the links on the pages are structured:
<img src="/images/1234.gif">
<img src="/images/picture.gif">
<img src="/images/example123.gif">
would this affect how the mod_rewrite works?
Thanks
Do you already have other mod_rewrite code that works? If not, then we're debugging your mod_rewrite configuration, and not the code itself.
If you don't already have working mod_rewrite code in your home directory .htaccess, try adding the directive
Options +FollowSymLinks
Also, flush your browser cache after any change to this code and after any change to the location of this code.
If you get any kind of error, check your server error log; It often will contain very useful information about the problem.
Your <img src...> links are fine.
Jim