【问题标题】:Htaccess Redirect / and index.php to HTTPSHtaccess 重定向 / 和 index.php 到 HTTPS
【发布时间】:2025-11-23 01:05:01
【问题描述】:

我正在尝试重定向:

http://website.com & http://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]

【问题讨论】:

    标签: .htaccess redirect https


    【解决方案1】:

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

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

    确保这是首要规则,并在新浏览器中对其进行测试。

    【讨论】: