How to redirect all HTTP requests to HTTPS

前端 未结 26 2136
小鲜肉
小鲜肉 2020-11-22 00:40

I\'m trying to redirect all insecure HTTP requests on my site (e.g. http://www.example.com) to HTTPS (https://www.example.com). I\'m using PHP btw.

26条回答
  •  囚心锁ツ
    2020-11-22 01:02

    Through .htaccess This will help.

    RewriteEngine On
    
    
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
    
    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
    

    Also, Refer this for More Detail. How To Redirect Http To Https?

提交回复
热议问题