How to redirect all HTTP requests to HTTPS

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

    To redirect all http requests to https , you can use :

    RewriteEngine on
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R]
    

    If mod-rewrite isn't enabled and you are on apache 2.4, you can also use a Redirect inside if directive to redirect http requests to https .

    Apache 2.4.

    
    Redirect / https://www.example.com/
    
    

提交回复
热议问题