我有一个在 apache Heroku 实例上运行的 Laravel 5 版本,我试图确保所有流量都通过 https 转换,但是我非常迷失。
我已成功启动并运行 SSL 证书。但是,使用 Heroku,您无法直接编辑服务器上的 .htaccess 文件。所以他们的建议是这一页 https://devcenter.heroku.com/articles/custom-php-settings的方法是设置一个 apache_app.conf 并通过将其放入 Procfile 中来告诉 Heroku 读取它:
web: vendor/bin/heroku-php-apache2 -C apache_app.conf public/
然而,当我这样做时,几乎我添加的任何类型的 HTTPS 重写规则都会导致重定向循环或应用程序错误。这是我当前的配置:
RewriteEngine on
#Normal way (in case you need to deploy to NON-heroku)
RewriteCond %{HTTPS} !=on
#Heroku way
RewriteCond %{HTTP:X-Forwarded-Proto} !https
#If neither above conditions are met, redirect to https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
我没有通过 .htaccess 处理重定向,而是通过this https://stackoverflow.com/questions/28402726/laravel-5-redirect-to-https method
HttpsProtocol 中间件会将每个 Web 路由重定向到 HTTPS 协议
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)