Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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:


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

try with this

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


share|improve this answer

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

Your Answer


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.