【发布时间】:2018-11-20 14:48:44
【问题描述】:
我有一个简单的路由,它处理从数据库重定向到正确的跟踪链接。路由本身看起来像这样 -
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]
过程文件
web: vendor/bin/heroku-php-apache2 -C apache_app.conf public/
2) 强制通过 https 重定向我的所有路由,使用 web.php 顶部的这个 sn-p -
if (env('APP_ENV') === 'prod') {
\URL::forceScheme('https');
}
在尝试通过 http:// 访问我的应用程序时 - 我 - 正在被重定向到 https:// 版本,看起来没问题。但是当我使用路由的 /en/go/xxxx 端点调查重定向链时,我得到了一些奇怪的链接,其中包括首先重定向回 http 版本,然后将其重定向回 https 版本。因此,当尝试在 iframe 中加载其中一个跟踪 url 时 - 我收到一个错误 -
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
【问题讨论】:
标签: php laravel heroku laravel-5