Forum Topic: rewriterule without Last Flag
I am trying to understand behaviour a bunch of rewriterule rules without Last flag
Consider my htaccess file location is http://localhost/h/
( Applications/AMPPS/www/h
)
Example 1:
RewriteRule anchor/(.+) /hello [R,ENV=lang:hi]
RewriteRule anchor /anchor/guess [R]
RewriteRule /hello /yes [R]
If I enter http://localhost/h/anchor/text
then what I think happen is
- First line
RewriteRule anchor/(.+) /hello [R,ENV=lang:hi]
‘s patternanchor/(.+)
matches and so it redirects tohttp://localhost/hello
, but as there is noL
flag, redirection tohttp://localhost/hello
is on hold, thus it goes below - Line second’s pattern
anchor
does not match with newhttp://localhost/hello
so this is skipped - third line’s pattern
/hello
matches withhttp://localhost/hello
and it finally redirects tohttp://localhost/yes
Things seems as per I though untill I see example below
Example 2:
RewriteRule foo/bar /tmp1/ [R]
RewriteRule foo/bar /tmp2/ [R]
RewriteRule (.+) /tmp3/ [R]
RewriteRule (.+) /tmp4/ [R]
RewriteRule hello /tmp6/ [R]
RewriteRule bar /tmp7/ [R]
RewriteRule hello /tmp8/ [R]
RewriteRule tmp7/ /tmp5/ [R]
same htaccess file location, I hit http://localhost/h/foo/bar
, I thought this happens
- first line’s pattern
foo/bar
matches with url, so it redirects tohttp://localhost/tmp1
, but as there is noL
, its on hold, it goes below - second line’s pattern
foo/bar
does not match withhttp://localhost/tmp1/
, so its skipped, ( if I remove all lines except first two, I see final redirects tohttp://localhost/tmp1/
) - third line’s pattern match with
http://localhost/tmp1/
and turned tohttp://localhost/tmp3/
- fourth line’s pattern matches, redirect to
http://localhost/tmp4/
- fifth line’s “hello” not matched redirects still is
http://localhost/tmp4/
- and now which thing spin my mind for last 3 hrs is sixth’s line
bar
matches .. and redirects tohttp://localhost/tmp7/
( remove last 2 lines to confirm ) how ? - seventh’s does not match as expected
- eighth line
tmp7/
matches withhttp://localhost/tmp7/
and then finally redirects tohttp://localhost/tmp5/
now question is why 6’th line’s bar
matches and if it can match with oldest url entered ( http://localhost/foo/bar
) then why it did not match on second line of same example and why it did not matched in second line of example 1 ?
remember all target pattern point to outside of the folder ( in parent, www, so that they can not hit back to the htaccess file again )