Use .htaccess to redirect HTTP to HTTPs

后端 未结 17 1614
刺人心
刺人心 2020-12-02 05:51

Please, don\'t recommend me the long and very detailed thread with more than 173 upvotes. It didn\'t work for me. I have also tried many others (1, 2, 3, 4). They all give m

17条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 06:30

    Add this in the WordPress' .htaccess file:

    RewriteCond %{HTTP_HOST} ^yoursite.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
    RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]
    

    Therefore the default WordPress' .htaccess file should look like this:

    
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    RewriteCond %{HTTP_HOST} ^yoursite.com [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
    RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]
    
    

提交回复
热议问题