Laravel强制使用.htaccess的HTTPS使用Amazon ELB进行过多重定向
把我的头发拔出来。我需要强制使用HTTPS,并在.htaccess文件中获得太多的重定向。根据我对Stack的研究,这应该是可行的。清除了缓存、cookies等等Laravel强制使用.htaccess的HTTPS使用Amazon ELB进行过多重定向,laravel,.htaccess,Laravel,.htaccess,把我的头发拔出来。我需要强制使用HTTPS,并在.htaccess文件中获得太多的重定向。根据我对Stack的研究,这应该是可行的。清除了缓存、cookies等等 <IfModule mod_rewrite.c> <IfModule mod_negotiation.c> Options -MultiViews </IfModule> RewriteEngine On RewriteCond %{HTTPS} o
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
选项-多视图
重新启动发动机
重写条件%{HTTPS}关闭
重写规则^(.*)$https://%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
#如果不是文件夹,则重定向尾部斜杠。。。
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)/$/$1[L,R=301]
#处理前控制器。。。
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index.php[L]
#句柄授权头
RewriteCond%{HTTP:Authorization}。
重写规则。*-[E=HTTP\U授权:%{HTTP:AUTHORIZATION}]
好的,算了。因为我在负载平衡器后面,所以我必须更换:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
与:
关于为什么需要该标题的更多信息:我有一个类似的问题(使用Codeigniter和AWS Classic ELB),但上述解决方案对我不起作用。我必须在https.conf文件中应用重写条件和规则,然后重新启动apache服务器。请参见此处了解如何操作。还值得注意的是,AWS不推荐.htaccess方法(不确定原因):
我在共享主机上与Laravel 6有类似的问题。当我配置CPanel将我的应用重定向到一个安全的
https
url时,它会无限地重定向
我的.htaccess
RewriteCond %{HTTP_HOST} ^biblioteca\.vallenateca\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.biblioteca\.vallenateca\.com$
RewriteRule ^/?$ "https\:\/\/biblioteca\.vallenateca\.com" [R=301,L]
我加了两行
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^biblioteca\.vallenateca\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.biblioteca\.vallenateca\.com$
RewriteRule ^/?$ "https\:\/\/biblioteca\.vallenateca\.com" [R=301,L]
它解决了这个问题。在AWS ec2 Linux 2和Laravel.htaccess中对我有效。谢谢
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^biblioteca\.vallenateca\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.biblioteca\.vallenateca\.com$
RewriteRule ^/?$ "https\:\/\/biblioteca\.vallenateca\.com" [R=301,L]