添加 www 时 RewriteOptions Inherit、InheritDown、InheritBefore 等的奇怪行为
我想要一个带有 RewriteEngine on
的子 .htaccess
,它继承父目录的 RewriteRule
。
好的(仅限父 .htaccess
且 RewriteEngine 打开
)
条件:
# /.htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L,QSA]
# /article/.htaccess
(Empty or without RewriteEngine on)
结果:
example.com/article/34 => www.example.com/article/34
父规则被忽略(至少在某些情况下)
条件:
# /.htaccess
RewriteEngine on
RewriteOptions InheritDown #or InheritDownBefore
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L,QSA]
# /article/.htaccess
RewriteEngine on
结果:
example.com/article/34 => example.com/article/34
父规则变得奇怪
条件:
# /.htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L,QSA]
# /article/.htaccess
RewriteEngine on
RewriteOptions Inherit #or InheritBefore
结果:
example.com/article/34 => www.example.com/34
I want to have a child .htaccess
with RewriteEngine on
that inherits parent directory's RewriteRule
s.
OK (only parent .htaccess
with RewriteEngine on
)
Condition:
# /.htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L,QSA]
# /article/.htaccess
(Empty or without RewriteEngine on)
Result:
example.com/article/34 => www.example.com/article/34
Parent rule ignored (at least in some cases)
Condition:
# /.htaccess
RewriteEngine on
RewriteOptions InheritDown #or InheritDownBefore
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L,QSA]
# /article/.htaccess
RewriteEngine on
Result:
example.com/article/34 => example.com/article/34
Parent rule becomes wierd
Condition:
# /.htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L,QSA]
# /article/.htaccess
RewriteEngine on
RewriteOptions Inherit #or InheritBefore
Result:
example.com/article/34 => www.example.com/34
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议根本不要使用
Inherit
或类似选项,而是尝试在RewriteEngine on
上使用尽可能少的.htaccess
文件。如果您需要在子
.htaccess
文件中使用RewriteEngine on
,您可以自己在其中重写所需的规则:(注意添加的
article/< /code> 最后一行)
I suggest not to use
Inherit
or similar options at all and instead, try to have as few.htaccess
files withRewriteEngine on
as possible.If you needed to have a
RewriteEngine on
in a child.htaccess
file, you can re-write desired rules in it yourself:(Note the added
article/
at last line)