Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess htaccess重写规则[R,L=301]标志不会停止它。为什么?_.htaccess_Url_Mod Rewrite_Https_Url Rewriting - Fatal编程技术网

.htaccess htaccess重写规则[R,L=301]标志不会停止它。为什么?

.htaccess htaccess重写规则[R,L=301]标志不会停止它。为什么?,.htaccess,url,mod-rewrite,https,url-rewriting,.htaccess,Url,Mod Rewrite,Https,Url Rewriting,.htaccess的开头是 RewriteEngine On #begin of rules for administration folder, redirect to https, if not https RewriteCond %{REQUEST_URI} ^/administration RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L=301] #end of rules f

.htaccess的开头是

RewriteEngine On

#begin of rules for administration folder, redirect to https, if not https
RewriteCond %{REQUEST_URI} ^/administration
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L=301]
#end of rules for administration folder

#===no rules for /administration folder below this line===
#the rest part of .htaccess
为什么.htaccess的其余部分仍然执行
https://www.mydomain.com/administration/index.php
?如何停止对管理文件夹后面的URL执行.htaccess文件的其余部分?我的代码出了什么问题?
谢谢。

这是因为您有语法错误。htaccess将忽略出错线路

RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
更改此项:-

RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L=301]
为此:-

RewriteRule .? https://%{HTTP_HOST}%{REQUEST_URI} [R=301]

在.htaccess文件顶部添加此行:

RewriteRule ^administration - [NC,L]

最近我遇到了一个类似的问题,在PHP聊天中,我从用户DaveRandom那里得到了一个非常有趣的答案:

“基本上,mod_rewrite有效地运行在一个循环中(这不是真的,但实际上它就是这样做的),而[L]标志就像PHP中的“continue”语句(它在当前迭代中停止处理下面的规则,但随后将从顶部再次开始处理规则)。因此,在您的规则中,第一次迭代匹配第一条规则,然后第二次迭代跳过第一条规则(它生成与输入相同的输出),然后匹配第二条规则。“


可能的解决方案:“如果您使用apache 2.4,使用[END]而不是[L]将是一个解决方案。”

删除
L
标志有时会导致问题。真的吗?我从来没有遇到过问题。在什么情况下?您几乎总是希望将[R]与[L]结合使用(即使用[R,L]),因为[R]标志本身会在URI前面加上前缀,但随后会将其传递到规则集中的下一个规则,这通常会导致“请求中的URI无效”警告。()