htaccess重定向/和index.php到HTTPS

时间:2018-09-26 22:32:37

标签: .htaccess redirect https

我正在尝试重定向:

http://website.comhttp://website.com/index.phphttps://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]

1 个答案:

答案 0 :(得分:1)

您可以将此规则用作最高规则

RewriteEngine On

RewriteCond %{HTTPS} !on [OR]
RewriteCond %{REQUEST_URI} ^/index\.php$ [NC]
RewriteRule ^(?:index\.php)?$ https://%{HTTP_HOST} [L,NE,R=301]

确保这是最高规则,然后在新的浏览器中对其进行测试。