代码之家  ›  专栏  ›  技术社区  ›  Bijan

Htaccess Redirect/and index.php到HTTPS

  •  1
  • Bijan  · 技术社区  · 6 年前

    我正在尝试重定向:

    http://website.com & http://website.com/index.php https://website.com

    我找到的所有解决方案都将重定向 http://website.com/test.php

    以下代码不适合我的需要:

    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 回复  |  直到 6 年前
        1
  •  1
  •   anubhava    6 年前

    你可以用这条规则作为你的规则 最高准则 :

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

    确保这是最重要的规则,并从新浏览器进行测试。