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

后端 未结 6 1155
我寻月下人不归
我寻月下人不归 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 12:03

    Problem is in this rule:

    #Force from http to https
    RewriteCond %{SERVER_PORT} 80 
    RewriteCond %{HTTP_HOST} !^bbb.example.co.uk/$
    RewriteRule ^(.*)$ https://bbb.example.co.uk/$1 [R=301]
    

    Change this rule to:

    #Force from http to https
    RewriteCond %{HTTPS} off 
    RewriteCond %{HTTP_HOST} =bbb.example.co.uk
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301]
    

    You have condition reversed due to use of ! at start and have an extra slash at end which will never be matched hence making your condition always return true.

    Make sure to clear your browser cache before testing this.

提交回复
热议问题