Forum Moderators: phranque

Message Too Old, No Replies

rewrite problem with [L] flag

rewrite .htaccess

         

vapetrov

8:15 pm on Mar 28, 2006 (gmt 0)


Hi!

Here the simple .htaccess file
---
RewriteEngine on
RewriteRule ^1\.html$ 2.html [L]

RewriteRule ^2\.html$ 3.html
---

In the folder presents files: 1.html, 2.html and 3.html

According of mod_rewrite docs flag [L] "Stop the rewriting process here and don't apply any more rewriting rules".

So, if I request 1.html I expect to get content of 2.html. But in practice both rules applied and I get content of 3.html. Here this example:
http://www.4oru.org/test/1.html

I have tested this on Apache/1.3.34 on linux and windows.

Why [L] flag don't working? What I do wrong?

jdMorgan

9:32 pm on Mar 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[L] stops processing for this pass through mod_rewrite. Unfortunately, in order to prevent hacks, once any rewrite is done, Apache will re-run mod_rewrite, mod_access, and several other modules, re-processing all httpd.conf and .htaccess access-control directives, so that a lower-level .htaccess file cannot be used to by-pass restrictions in httpd.conf and higher-level .htaccess files.

In order to solve your problem, you must use RewriteCond and the variable THE_REQUEST to examine the original client (browser) request, and apply the rule only on the first pass through mod_rewrite.

FYI, the contents of THE_REQUEST might be:

GET /2.html HTTP/1.1

so make sure to account for the method, spaces, and protocol in the RewriteCond pattern.

Jim