apache HTTP:X-Forwarded-Proto in .htaccess is causing redirect loop in dev environment

前端 未结 2 514
旧巷少年郎
旧巷少年郎 2020-11-29 18:31

I\'ve had to update my .htaccess from this:

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

to this:

相关标签:
2条回答
  • 2020-11-29 18:46

    To make it work in both environments you can combine both conditions:

    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
    
    0 讨论(0)
  • 2020-11-29 19:00

    I had a special case for a shared hosting (masterhost), everything was failing except:

      RewriteCond %{HTTP:X-Forwarded-Port} !443
      RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
    
    0 讨论(0)
提交回复
热议问题