A series of re-recordings without Last [L] Flag

UPDATE: Today I kind of figured out what the problem is: now take a look at the smaller version

RewriteCond %{REQUEST_FILENAME} (.+)
RewriteRule first /landingpage1.php [R,ENV=lang:hi]

RewriteCond %{REQUEST_FILENAME} (.+)
RewriteRule second /landingpage2.php?id=%1&%{ENV:lang} [R,L]

      

The location of my htaccess is / www / h / folder if I type localhost / h / firstsecond it returns localhost / landingpage1.php the template fails on 4th line but if I find localhost / h / first / second, the problem starts, does it = land on localhost / landingpage2.php? id = localhost / landingpage1.php & hi, actually once, just once, I don't know how, during the experiment I find out that from localhost / h / first / second url it is redirected with the first rewriting line, something like localhost / landingpage1.php // second and of course we can see the second line is working, I've seen similar behavior with Alias โ€‹โ€‹"redirect" too, if your url has something in the folder it adds the rest part into the final redirected url along with the query string.

so when localhost / h / firstsecond works fine but localhost / h / first / second does not, I know, probably close to know what is going on.

ARCHIVE:

I'm trying to figure out the behavior of a bunch of rewriterule rules without the last flag Consider that my htaccess file location is 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 localhost / h / anchor / text what I think is

  • The first line of the RewriteRule anchor /(.+)/ hello [R, ENV = lang: hi] pattern "anchor /(.+)" matches and therefore redirects to localhost / hello, but since there is no L, the redirect to localhost / hello is at standby mode, so it goes below

  • The second "anchor" string pattern does not match the new http: // localhost / hello, so this is skipped

  • third line / hello pattern matches localhost / hello and finally redirects to localhost / yes

Things seem to me, although I don't see an 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 location of htaccess file, I hit url localhost / h / foo / bar, I thought this was happening
1. The pattern of the first line "foo / bar" matches the url, so it redirects to http: // localhost / tmp1 /, but since L is missing it is on hold, it drops below

  1. the pattern of the second line "foo / bar" does not match http: // localhost / tmp1 /, so it is skipped (if I remove all lines except the first two, I see the final redirects to http: // local / tmp1 /)

  2. match the third line to http: // localhost / tmp1 / and access http: // localhost / tmp3 /

  3. match the fourth line, redirect to http: // localhost / tmp4 /

  4. the fifth line "hello" doesn't match redirects is still http: // localhost / tmp4 /

  5. and now what got me thinking for the last 3 hours matches the sixth line "bar" and redirects to http: // localhost / tmp7 / (delete the last 2 lines to confirm) how?

  6. the seventh is not as expected

  7. the eighth line tmp7 / matches http: // localhost / tmp7 / and then finally redirects to http: // localhost / tmp5 /

Now the question is why does the 6th line match "bar" and if it can match the oldest url (http: // localhost / foo / bar) then why did it not match the second line of the same example and why doesn't it match in the second line of example 1?

remember all template target points outside the folder (in parent, www so they can't go back to the htaccess file again)

+3


source to share


2 answers


First of all, a very good question with a lot of details.

If you include RewriteLog

, you will notice that it is caused by this line (when you ask for a URL http://localhost/h/first/second

):

add path info postfix: /landingpage1.php/second

      

There was a bug specifically raised for this issue on Apache.org.



This happens if you omit L

or (i.e. ) flags from . DPI

Discard Path Info

RewriteRule

It will behave well if you use:

RewriteCond %{REQUEST_FILENAME} (.+)
RewriteRule first /landingpage1.php [R,DPI,ENV=lang:hi]

RewriteCond %{REQUEST_FILENAME} (.+)
RewriteRule second /landingpage2.php?id=%1&%{ENV:lang} [R,L]

      

+2


source


  • the pattern of the first line "foo / bar" is the same as the url, so it redirects to http: // localhost / tmp1 /, but since L does not exist, it is suspended, it is below


No, this is not how it works because of the flag [R]

that the redirect issues. The redirect starts a new request / response cycle and all RewriteRules will start over from the beginning. The same will happen with [L]

or without a flag .

0


source







All Articles