Forcing http using .htaccess

前端 未结 2 1696
南方客
南方客 2021-02-02 00:01

This is the script I have right now, how do I have my script force all traffic to http, currently it is doing the exact opposite, it is forcing all traffic to https.

         


        
2条回答
  •  逝去的感伤
    2021-02-02 01:03

    You want to check that HTTPS is on:

    RewriteEngine On
    RewriteCond %{HTTPS} on
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    And if it is on (%{HTTPS} on), redirect to http://. There is no mod_rewrite variable called %{HTTP}, only %{HTTPS} which can be "on" or "off".

    The reason why you were getting the too many redirects error is because:

    RewriteCond %{HTTP} !=on
    

    is always true no matter if the request is http or https, since the variable doesn't exist, it will never be equal to "on". Therefore, even if the request is http, you keep getting redirected to the same URL (http).

提交回复
热议问题