Forum Moderators: phranque

Message Too Old, No Replies

Modrewrite only in case when a file does not exist

         

stormshield

3:03 pm on Oct 6, 2006 (gmt 0)

10+ Year Member



Hi,

I have 2 folders with jpgs. When a file in the fist one does not exist, I'd like to make a rewrite to the other folder. I tried this very simple rule:

RewriteRule ^folder1/([^/]*).jpg folder2/$1.jpg

I thought it would work because it usually did when it comes to html files. However, this time what it does it rewrite the jpgs from the first folder no matter what, which results in 404 errors.

Any ideas?

jdMorgan

3:53 pm on Oct 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Reading your description of the problem, it's clear that you must check to see if the file exists before rewriting. This would require the use of a directive such as

RewriteCond %{REQUEST_FILENAME} -f

ahead of any rewriterule you might wish to invoke if the file exists, or

RewriteCond %{REQUEST_FILENAME} !-f

ahead of any rule you maight want to invoke if the file does not exist.

For more information, see the RewriteCond directive in the mod_rewrite documentation.

Jim

stormshield

4:01 pm on Oct 6, 2006 (gmt 0)

10+ Year Member



Thanks Jim
I didn't know the RewriteCond thing very well, i'll have a look at it now.