Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to match URLs of this type:

http://www.example.com/image/12345

I'd then like to check whether this file exists:

http://www.example.com/files/image_12345.jpg

If it does, I'd like to rewrite the URL to point to that file.

If it doesn't I'd like to rewrite the URL to point to my image-generating script:

http://www.example.com/img_gen.php?id=12345

Here's what I've got so far:

RewriteCond %{REQUEST_FILENAME} ^/image/([0-9]+)$
RewriteCond %{DOCUMENT_ROOT}/files/images_%1.jpg !-f
RewriteRule ^image/([0-9]+)$ img_gen.php?id=$1 [L]

RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^image/([0-9]+)$ /files/images_$1.jpg [L]

But all I'm getting is a 404.

share|improve this question
    
Have you tried creating and reviewing an Apache rewrite log? httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritelog - may help with diagnosis and you can paste the output in your question. –  EightBitTony May 14 '12 at 13:39
    
I wish I could, but I'm on a shared host. Maybe I'll try it locally on a MAMP environment. –  jawns317 May 14 '12 at 13:48
    
You can add the rewrite log commands to your .htaccess file - see the first answer so far –  EightBitTony May 14 '12 at 13:50

1 Answer 1

If you can't figure out what your Rewrite Rules are doing you should enable RewriteLog with some increased verbosity:

RewriteLogLevel 3
RewriteLog "/var/log/rewrite.log"

This should give you a pretty good starting position in further investigation of what's going on wrong.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.