How to redirect all HTTP requests to HTTPS

前端 未结 26 2154
小鲜肉
小鲜肉 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:54

    Add the following code to the .htaccess file:

    Options +SymLinksIfOwnerMatch
    RewriteEngine On
    RewriteCond %{SERVER_PORT} !=443
    RewriteRule ^ https://[your domain name]%{REQUEST_URI} [R,L]
    

    Where [your domain name] is your website's domain name.

    You can also redirect specific folders off of your domain name by replacing the last line of the code above with:

    RewriteRule ^ https://[your domain name]/[directory name]%{REQUEST_URI} [R,L]
    

提交回复
热议问题