Forum Moderators: phranque

Message Too Old, No Replies

Image mod_rewrite

         

internetheaven

5:22 pm on Nov 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm trying to get:

/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.

jdMorgan

7:50 pm on Nov 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A couple of questions:

Is the code in httpd.conf or in .htaccess?

Do you have any other working RewriteRules?

Jim

internetheaven

8:10 pm on Nov 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's in .htaccess

Yes, there is a mod_rewrite in another folder of the site which is working fine but it is for dynamic-static pages as opposed to images. There is no mod_rewrite in the root folder, just in the html pages subfolder.

jdMorgan

12:41 am on Dec 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok, the difference between httpd.conf and .htaccess is that in .htaccess, the RewriteRule can't "see" the leading slash, so that may have broken your rule.

Try:


RewriteEngine on
RewriteCond %{REQUEST_URI} !^/images/mnt/errorgif\.gif$
RewriteRule [b]^im[/b]ages/mnt/.+\.gif$ /images/mnt/errorgif.gif [L]

The RewriteCond will prevent a potential infinite loop when /images/mnt/errorgif.gif is requested.

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]

Jim

internetheaven

11:06 am on Dec 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the help but I can't seem to get it to work:

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

jdMorgan

2:39 pm on Dec 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code is intended to go into your Web root directory, along with your "home page."

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

ahead of the RewriteEngine on line.

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