php – Heroku上的Laravel强制执行HTTP
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – Heroku上的Laravel强制执行HTTP,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2455字,纯文字阅读大概需要4分钟。
内容图文
![php – Heroku上的Laravel强制执行HTTP](/upload/InfoBanner/zyjiaocheng/718/3095cad3b29441eb96069ec3e3230eac.jpg)
我有一个简单的路由,处理重定向到数据库中正确的跟踪链接..路由本身看起来像这样 –
Route::get('/{language}/go/{operator}', function($language, $operator) {
$operator = Operator::where('language',$language)->where('name',$operator)->first();
$tracking_url = $operator->visit_url;
if( isset($_GET['session_id']) ) $session_id = strip_tags($_GET['session_id']);
else $session_id = 1;
if( $operator->dynamic_parameter ) {
$full_url = $tracking_url.'&'.$operator->dynamic_parameter.'='.$session_id;
}
else {
$full_url = $tracking_url;
}
return redirect($full_url)->header('Referrer-Policy', 'no-referrer');
});
整个网站驻留在HTTPS(由heroku处理)上,作为重定向链的额外层,我又添加了2个东西 –
1)添加一些额外的服务器配置(apache_app.conf)并使用procfile加载它 –
apache_app.conf
DirectoryIndex index.php index.html index.htm
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
procfile
web: vendor/bin/heroku-php-apache2 -C apache_app.conf public/
2)强制所有路由通过https重定向,使用web.php顶部的这个片段 –
if (env('APP_ENV') === 'prod') {
\URL::forceScheme('https');
}
在尝试通过http://访问我的应用程序时,我将-am-重定向到https://版本,似乎没问题.但是当我使用route的/ en / go / xxxx端点调查重定向链时,我得到了一些奇怪的链接,其中包括首先重定向回http版本,然后将其重定向回https.因此,当尝试在iframe中加载其中一个跟踪网址时 – 我收到错误 –
Mixed Content: The page at 'https://www.website.com/us/reviews/xxxxx' was loaded over HTTPS, but requested an insecure resource 'http://www.website.com/us/go/xxxxx?session_id=1'. This request has been blocked; the content must be served over HTTPS.
重定向链看起来像这样 –
Result
https://www.website.com/us/go/xxxxx/?session_id=332
301 Moved Permanently
http://www.website.com/us/go/xxxxx?session_id=332
301 Moved Permanently
https://www.website.com/us/go/xxxxx?session_id=332
302 Found
https://track.xxxxx.com/visit/?bta=123456&nci=654321&utm_campaign=website_camapign&afp=332
解决方法:
在您的apache配置文件中,确保您的ServerName设置为https://www.website.com而不是http://www.website.com.
从docs:
Sometimes, the server runs behind a device that processes SSL, such as a reverse proxy, load balancer or SSL offload appliance. When this is the case, specify the https:// scheme and the port number to which the clients connect in the ServerName directive to make sure that the server generates the correct self-referential URLs.
这可能是根据需要使用http而不是https生成第一个重定向的原因.
内容总结
以上是互联网集市为您收集整理的php – Heroku上的Laravel强制执行HTTP全部内容,希望文章能够帮你解决php – Heroku上的Laravel强制执行HTTP所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。