Use .htaccess to redirect HTTP to HTTPs

后端 未结 17 1587
刺人心
刺人心 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条回答
  •  一向
    一向 (楼主)
    2020-12-02 06:36

    In my case, the htaccess file contained lots of rules installed by plugins like Far Future Expiration and WPSuperCache and also the lines from wordpress itself.

    In order to not mess things up, I had to put the solution at the top of htaccess (this is important, if you put it at the end it causes some wrong redirects due to conflicts with the cache plugin)

    
    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
    

    This way, your lines don't get messed up by wordpress in case some settings change. Also, the section can be repeated without any problems.

    I have to thank Jason Shah for the neat htaccess rule.

提交回复
热议问题