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.

Instead of directly accessing images, I need to use RewriteRule to redirect a set of images to be accessed via a script.

A RewriteRule is used for it:

RewriteRule ^Images/test/([^.\/]*)\.png /image.php?file=$1.png [R=301,L]

I would expect this to change:

www.example.com/Images/test/123.png

into

www.example.com/image.php?file=123.png

But it does not do it.

But If I change the RewriteRule to the following:

RewriteRule ^Images2/test/([^.\/]*)\.png /image.php?file=$1.png [R=301,L]

The following works:

www.example.com/Images2/test/123.png

into

www.example.com/image.php?file=123.png

The difference is that Images exsits while Images2 does not exist. Is it possible to it working with an existing folder.

Any help on how to get the top example working?

Update: After carefully looking through the mod_rewrite documentation, I found this:

...Note that mod_rewrite tries to guess whether you have specified a file-system path or a URL-path by checking to see if the first segment of the path exists at the root of the file-system...

It seems that if the path is interpreted as a URL-path it works and if it is interpreted as a file-system path it fails.

share|improve this question

2 Answers 2

Try changing the beginning of your anchor to ^/, just a hunch. I have not personally used RewriteRules anchored to the beginning of the line that do not begin with a slash, but I can see how that might create some weirdness within the engine.

share|improve this answer
1  
It depends on the setting of RewriteBase. –  Michael Hampton Jan 24 '13 at 17:35
    
I have tried this, but it did not help. RewriteBase is set to the root of the apache2 www folder. –  Badran Jan 24 '13 at 18:12
    
@user155908 Just to make sure I'm not misunderstanding you, RewriteBase should be a URI and not a filesystem path. (if you meant that it's set to /, you're fine) –  Andrew B Jan 24 '13 at 18:22
    
@Andrew B It is set to /. –  Badran Jan 24 '13 at 18:29

try with this

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$0 [L]

luck!!

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.