一系列重写规则无尾页[L]标志 [英] A series of rewriterule without Last [L] Flag

查看:225
本文介绍了一系列重写规则无尾页[L]标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新: 今天我有点找出问题是:现在就来看看小版本

UPDATE: today I kind of find out what the problem is : now take a look at 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]

我的htaccess的文件位置是/ WWW / H /文件夹 如果我输入localhost / H / firstsecond,它返回本地主机/ landingpage1.php,图案不满意的4号线 但是如果我输入localhost / H /第一/第二,问题开始,它=土地在localhost / landingpage2.php ID =本地主机/ landingpage1.php和放大器;喜,居然有一次,只是有一次我不知道我怎么了,发现实验过程中,将localhost / H /第一/第二个URL,它与第一个重写规则行类似本地主机/ landingpage1.php //秒,ofcourse这样,我们看到第二行的工作重新定向, 我已经看到了这种用别名行为定向过,如果有一些文件夹跟踪到您的网址,它增加了余下的部分到最后重定向的URL与查询字符串。

my htaccess file location is /www/h/ folder if I type localhost/h/firstsecond, it returns localhost/landingpage1.php , pattern is not satisfied on 4th line but if I type localhost/h/first/second, problem starts , it = lands on localhost/landingpage2.php?id=localhost/landingpage1.php&hi , actually one time, just one time I do not know how, I find out during experiment that with localhost/h/first/second url , it redirected with first rewriterule line something like localhost/landingpage1.php//second , and ofcourse this way we see second line works , I have seen this kind of behavior with Alias "redirect" too, if there is something folder trail into your url , it adds remaining part into final redirected url along with query string.

所以当本地主机/ H / firstsecond工作正常,但本地主机/ H /第一/第二不,我知道大概接近就知道是怎么回事。

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

ARCHIEVE:

我想了解的行为一堆重写规则的规则没有最后标志 考虑我的htaccess的文件位置为localhost / H /(应用/ AMPPS / WWW / H)

I am trying to understand behaviour a bunch of rewriterule rules without Last flag Consider my htaccess file location is localhost/h/ ( Applications/AMPPS/www/h )

例1:

RewriteRule anchor/(.+) /hello [R,ENV=lang:hi]
RewriteRule anchor /anchor/guess [R]
RewriteRule /hello /yes [R]

如果我输入localhost / H /锚/文 那么我认为发生的是

If I enter localhost/h/anchor/text then what I think happen is

  1. 第一行重写规则锚/(.+)/你好[R,ENV =郎咸平:喜]的模式锚/(.+)的比赛,因此它重定向到l​​ocalhost /打招呼,但因为有是不使用L标志,重定向到l​​ocalhost /你好处于暂停状态,因此低于

  1. First line RewriteRule anchor/(.+) /hello [R,ENV=lang:hi] 's pattern "anchor/(.+)" matches and so it redirects to localhost/hello , but as there is no L flag, redirection to localhost/hello is on hold ,thus it goes below

第二行的模式锚不与新的HTTP匹配://本地主机/打招呼所以这将跳过

Line second's pattern "anchor" does not match with new http:// localhost/hello so this is skipped

事情似乎按照我虽然直到我看到下面的例子 实施例2:

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]

相同htaccess文件的位置,我打本地主机URL / H /富/酒吧, 我认为出现这种情况
1.第一行的模式富/酒吧与URL匹配,因此它重定向到http://本地主机/ TMP1 /,但因为没有L,它的搁置,它低于

same htaccess file location, I hit url localhost/h/foo/bar , I thought this happens
1. first line's pattern "foo/bar" matches with url , so it redirects to http:// localhost/tmp1/ , but as there is no L , its on hold , it goes below

第二行的模式富/酒吧不以http匹配://本地主机/ TMP1 /,因此其跳过,(如果我删除除前两行的所有,我看到的最后重定向到http://本地主机/ TMP1 /)

  1. second line's pattern "foo/bar" does not match with http:// localhost/tmp1/ , so its skipped, ( if I remove all lines except first two , I see final redirects to http:// localhost/tmp1/)

第三行的模式匹配以http://本地主机/ TMP1 /转身到http://本地主机/ TMP3 /

third line's pattern match with http:// localhost/tmp1/ and turned to http:// localhost/tmp3/

第四条线的模式相匹配,重定向到http://本地主机/ tmp4 /

fourth line's pattern matches, redirect to http:// localhost/tmp4/

第五行的你好不匹配的重定向仍然是http://本地主机/ tmp4 /

fifth line's "hello" not matched redirects still is http:// localhost/tmp4/

而现在这件事自旋我心中最后的3小时是第六的路线栏中的匹配..和重定向到http://本地主机/ tmp7 /(除去最后两行确认)怎么样?

and now which thing spin my mind for last 3 hrs is sixth's line "bar" matches .. and redirects to http:// localhost/tmp7/ ( remove last 2 lines to confirm ) how ?

第七的不匹配预期

第八行tmp7 /匹配以http://本地主机/ tmp7 /然后终于重定向到http://本地主机/ TMP5 /

eighth line tmp7/ matches with http:// localhost/tmp7/ and then finally redirects to http:// localhost/tmp5/

现在的问题是,为什么6'th行的酒吧的比赛,如果能与最古老的URL匹配输入(HTTP://本地主机/富/条),那么它为什么在第二行相同的例子,为什么它不匹配没有在实施例1的第二行匹配?

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 ?

记住所有的目标模式指向文件夹之外(WWW的父母,使他们不能打回htaccess文件再次)

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 )

推荐答案

首先,有很多细节都一个很好的问题。

First of all a very good question with lots of details.

如果您启用 RewriteLog ,你会发现其实这是可能出自这条线(当你请求的http://本地主机/ H /第一/秒 URL):

If you enable RewriteLog you will notice this is actually being caused by this line (when you request http://localhost/h/first/second URL):

add path info postfix: /landingpage1.php/second

有专门针对这一问题上Apache.org提出了问题。

这发生在你忽略 DPI (即放弃路径信息重写规则。

This happens when you omit L or DPI (i.e. Discard Path Info) flags from 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]

这篇关于一系列重写规则无尾页[L]标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆