Mod_Rewrite ignores [L] directive?


Hi there,

I seem to have a weird problem that is affecting my DH setup but not on my local dev environment.

Contents of .htaccess are :

RewriteEngine On

RewriteRule ^(robots.txt|favicon.ico|p3p.xml)$ skin/static/includes/$1 [L,NC]
RewriteRule ^static/(.).(css|js)$ skin/static/index.php?uri=$1.$2 [L,NC]
RewriteRule ^static/(.
)$ skin/static/$1 [L,NC]
RewriteRule ^documentation/?(.)$ /documentation/$1 [L,NC]
RewriteRule ^.
$ index.php

What’s actually happening is

/documentation/* works fine, no problems

Input URL

which should map to

is actually mapping to

It appears that apache is ignoring the [L] last directive and continuing to rewrite down to the last rule.

Any Ideas?



When you use the mod_rewrite in .htaccess, it acts differently compared to whe you use them in the httpd.conf file.

What happens is after it see [L] flag, or after finishing any rewrite and hitting the end, the Apache will put the new URI into the system again.
So, unless you use one of loop stopping techniques, your rewriterule can go into the endless loop and cause 500 error.

Adding this before any other rule should stop the looping.
RewriteCond %{ENV:REDIRECT_STATUS} =200
RewriteRule ^ - [L]

This method has a side effect of preventing any redirected URI, such as any internal redirect from going through following RewriteRules, and you should be careful.

There are other methods, too.
I wrote about these in my site, as well:

...* I’d be happier if DH had free shared SSL and redundant server setup. ..*.