How to redirect all HTTP requests to HTTPS

前端 未结 26 2155
小鲜肉
小鲜肉 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 00:59

    Using the following code in your .htaccess file automatically redirects visitors to the HTTPS version of your site:

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

    If you have an existing .htaccess file:

    Do not duplicate RewriteEngine On.

    Make sure the lines beginning RewriteCond and RewriteRule immediately follow the already-existing RewriteEngine On.

提交回复
热议问题