Regex 不带最后[L]标志的一系列重写规则
更新: 今天我发现了问题所在:现在看一看较小的版本Regex 不带最后[L]标志的一系列重写规则,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,更新: 今天我发现了问题所在:现在看一看较小的版本 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/folder 若我
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/folder
若我输入localhost/h/firstsecond,它将返回localhost/landingpage1.php,第4行的模式不满足
但是如果我输入localhost/h/first/second,问题就开始了,它=lands on localhost/landingpage2.php?id=localhost/landingpage1.php&hi,实际上有一次,只有一次我不知道怎么做,我在实验中发现,使用localhost/h/first/second url,它使用第一行规则重定向,比如localhost/landingpage1.php///second,当然我们看到第二行是这样工作的,
我在别名“redirect”中也看到过这种行为,如果在url中有文件夹痕迹,它会将剩余部分与查询字符串一起添加到最终重定向的url中
因此,当localhost/h/firstsecond工作正常,但localhost/h/first/second工作不正常时,我很可能不知道发生了什么
拱门:
我试图理解一堆没有最后一个标志的重写规则
考虑我的HTAccess文件位置是LoalHoal/H/(应用程序/ AMPPS /WWW/H)
例1:
RewriteRule anchor/(.+) /hello [R,ENV=lang:hi]
RewriteRule anchor /anchor/guess [R]
RewriteRule /hello /yes [R]
如果我输入localhost/h/anchor/text
那么我想发生的是
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 localhost/h/foo/bar,
我以为会发生这种事
1.第一行的模式“foo/bar”与url匹配,因此它重定向到http://localhost/tmp1/,但由于没有L,所以它处于保留状态,所以它位于下面
不,这不是它的工作原理,因为
[R]
标志会发出重定向。重定向将开始一个新的请求/响应周期,任何重写规则都将从头开始。无论是否使用[L]
标志,同样的事情也会发生。首先,这是一个非常好的问题,有很多细节
如果启用RewriteLog
,您将注意到这实际上是由此行引起的(当您请求http://localhost/h/first/second
URL):
当您省略L
或RewriteRule
中的标志时,会发生这种情况
如果您使用:
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]
但是如果它发出重定向,那么它应该发出第一个重定向,就像从第一行开始一样,因为我的htaccess文件不在根文件夹(或Application/AMPPS/www)中,而是位于Application/AMPPS/www/h中,所以在这种情况下,我想它不应该再次命中htaccess文件。你的观点是什么?第二,如果我同意你的观点,它在看到[R]而不管L标志时都会发出重定向,同样的逻辑,我不知道为什么它令人满意的第7行“RewriteRule bar/tmp7/[R]”太棒了,我以前不知道任何标志DPI。我发现mod Alias的重定向也有类似的功能,因为我们不使用任何标志,那么它呢?“重定向”是正常的默认值吗?你能用
RedirectMatch
测试吗?
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]