0

Consider this simple rule to hide an ugly URL from the visitor:

RewriteRule ^/CleanPage.html$ /index.php?ugly_parameter=yuck&somevar=12 [L]

This rule seems to be producing two sets of "rule runs" in the log. First, it runs all the rules, until it finds that CleanPage.html matches.

At this point, it should be done, but instead it does something stupid: it takes the complex url, "index.php?ugly_parameter=yuck&somevar=12" and starts over from the begining trying to match it to another rule!

How do I tell it that "index.php?ugly_parameter=yuck&somevar=12" is my "final answer" and to not waste time trying to see if it matches anything else? I thought that's what the "[L]" flag was for?

Nick
  • 4,503
  • 29
  • 69
  • 97

1 Answers1

1

The [L] parameter merely indicates that this is the last rule to be considered on the currently rewritten URL, however it does not cover internal redirects.

I will assume that you have changed the RewriteRule from its original form somewhat, and that you are trying to use the Rule inside a .htaccess file -- in that case the behavior you observe would be expected (but also in that case, the Rule would read RewriteRule ^CleanPage.html$ /index.php?ugly_parameter=yuck&somevar=12 [L] instead, i.e. without the leading slash), as stated in http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule under the L-flag.

When you use a RewriteRule inside a .htaccess-file (or a <Directory>-context), Apache httpd has to reinject the resulting rewritten URL into the Apache kernel because it is way too late in the processing to simply change the filename -- the the resolution of the URL into a filename has already happened, otherwise httpd would not have known where to look for the .htaccess file you are using. Reinjecting the URL basically starts the entire request process anew -- including any and all RewriteRules.

If you want to avoid this, you have to specify the rules inside the <VirtualHost>-context in the Apache httpd configuration file. In that case, the rule can be applied quite a bit before it is too late to change subsequent processing, and the rule will only be applied once.

If I made any assumptions that are wrong, please post the output of RewriteLog with LogLevel 3 for further analysis.

eike
  • 176
  • 4