【发布时间】:2017-07-14 13:41:51
【问题描述】:
我想将所有non-www 和所有non-https 重定向到https://www URL。
我有一个包含以下代码的 .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}$1
这适用于根路径:
OK https://www.mywebsite.com => https://www.mywebsite.com
OK http://mywebsite.com => https://www.mywebsite.com
OK https://mywebsite.com => https://www.mywebsite.com
OK http://www.mywebsite.com => https://www.mywebsite.com
但是当我尝试进入子文件夹时存在(某种)错误:
OK https://www.mywebsite.com/tmp => https://www.mywebsite.com/tmp
KO https://mywebsite.com/tmp => https://www.mywebsite.com/tmp/tmp
KO http://www.mywebsite.com/tmp => https://www.mywebsite.com/tmp/tmp
KO http://mywebsite.com/tmp => https://www.mywebsite.com/tmp/tmp
如您所见,再次附加子文件夹并给出 404 错误。
如何修复我的 .htaccess 规则以获得预期的重定向?
非常感谢
【问题讨论】:
标签: php apache .htaccess redirect mod-rewrite