首页 文章

.htaccess永久重定向HTTP到HTTPS

提问于
浏览
1

我目前使用以下.htaccess从所有网址的末尾删除.php http://littleloans.co.za/index.php

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ $1.php [L,QSA]
</IfModule>

我刚买了SSL证书,想要保留当前的规则,但也要从http重定向到https

有什么解决方案吗?永久重定向

3 回答

  • 1

    只需在你的.htaccess中使用它:

    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
    
  • 1

    添加此作为第一条规则应该有效 .

    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
  • 1

    试试:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    #redirect http to https and www to  non-www
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} ^www\.
    RewriteRule ^ https://example.com%{REQUEST_URI} [NE,L,R=301]
    #remove .php
    RewriteCond %{SCRIPT_FILENAME}.php -f
    RewriteRule ^(.*?)/?$ $1.php [L,QSA]
    </IfModule>
    

相关问题