apache - Why is this [L] flag failing to prevent application of the next rewrite rule? -


i thought "l" flag supposed prevent subsequent rules being applied. yet in example:

rewriterule foo bar [l] rewriterule bar qux 

i http://mysite/foo rewritten http://mysite/qux. expected http://mysite/bar. missing here?

the behavior of [l] flag quite poorly described in apache docs. in order understand how works first need know how apache handles rewriterules. let's take simple example

rewriterule ^something /somethingelse #1 rewriterule ^somewhere /somewhereelse #2  rewriterule ^someplace /anotherplace  #3 

in situation multiple rules , no [l] flags, if request /something, apache rewrite /somethingelse (as per #1), try rules #2 , #3. after rules processed checks if url came out of rewriterules same url went in. if it's not, apache starts processing rules again, until input===output (or maximum number of redirects met, prevent infinite loops).

now, if change rule #1 , add [l] it, , request /something again, apache rewrite /somethingelse (as per #1), , stop processing rules, i.e., not process #2 , #3. then, since url came out not same url went in (that's crux here), processing restarts, , rules #2 , #3 processed anyway (and #1 also, doesn't anymore).

in example if want prevent /bar being redirected /qux when rewritten first rewriterule, can use

rewriterule foo bar [l] rewritecond %{the_request} ^get\ /bar rewriterule bar qux 

that rewrite /bar /qux only if user requested /bar, , not if url rewritten /foo /bar first.

the trick here %{the_request} contains exact http header used request, , doesn't change when rewrite url, using variable can check original request (in contrast %{request_uri}, change on every rewrite).


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -