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

I have a mod_rewrite rule to pass requests to a front controller, but I can't seem to get it working without an [R] flag.

The set-up isn't entirely straightforward, I have an aliased directory inside the web root, and I'm trying to rewrite into that directory. If I ignore that directory, I can get it to rewrite just fine.

If I use:

Alias /main /some/path/
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule /main/(.*)$ /main/index.php/$1 [R]

It works as expected, and index.php receives the value as a parameter, but since it's using the [R] flag, a request for /main/some-param ends up as a URI ending in /main/index.php/some-param and I'm aiming to have it transparent.

Without the [R], the request results in a 404 and a log entry along the lines of File does not exist: /mywebroot/main which seems odd.

Is there anything about using an Alias here that's causing it or is it an error with the rule itself?

share|improve this question
up vote 3 down vote accepted

It's the Alias that's causing the problem - the rewritten version is assumed to be a path to an actual file, (either an absolute filesystem path or one relative to the DocumentRoot). If you add a PT flag, the Alias will get correctly applied.

share|improve this answer
This works perfectly, thanks. I really should have noticed [PT] given how close it is to [R] in the RewriteRule docs, and it specifically mentions it helping with the use of mod_alias and mod_rewrite. – Simon Mar 17 '12 at 10:48

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.