我正在尝试重定向:
http://website.com和http://website.com/index.php至https://website.com
我找到的所有解决方案都将http://website.com/test.php(具有登录名)重定向到401页。我只希望/和/index.php重定向到HTTPS
以下代码无法满足我的需求:
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
和
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
答案 0 :(得分:1)
您可以将此规则用作最高规则:
RewriteEngine On
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{REQUEST_URI} ^/index\.php$ [NC]
RewriteRule ^(?:index\.php)?$ https://%{HTTP_HOST} [L,NE,R=301]
确保这是最高规则,然后在新的浏览器中对其进行测试。