How to redirect all HTTP requests to HTTPS

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

    This redirects all the URLs to https and www

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

提交回复
热议问题