.htaccess - “Too many redirects” when trying to force https

后端 未结 6 1153
我寻月下人不归
我寻月下人不归 2021-01-31 11:19

I am trying to force a subfolder (/bbb/) of my root domain to show always as https. Also my .htaccess file take care of the extensions of the pages.

I have

6条回答
  •  走了就别回头了
    2021-01-31 11:56

    If you have a proxied server or if you're using shared hosting then sometimes you'll get a free SSL via CloudFlare. And if you are using a framework like CodeIgniter or Laravel then you always have a route file. So sometimes the answer I have given above might not work.

    In that case when you try to redirect to https you might get unlimited loops. So to resolve that you could try below:

    RewriteEngine On
    
    # If we receive a forwarded http request from a proxy...
    RewriteCond %{HTTP:X-Forwarded-Proto} =http [OR]
    
    # ...or just a plain old http request directly from the client
    RewriteCond %{HTTP:X-Forwarded-Proto} =""
    RewriteCond %{HTTPS} !=on
    
    # Redirect to https version
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

提交回复
热议问题