如何在 Laravel 4 中将一个路由重定向到 HTTPS 而将所有其他路由重定向到 HTTP?

How to redirect one route to HTTPS and all the others to HTTP in Laravel 4?

我想将我网站上的结帐页面提供为“HTTPS”,但我网站上的所有其他页面都需要保持“HTTP”。我的 SSL 证书已正确安装,并且 SSL 路由在我的服务器上运行良好。

我在 filters.php 中添加了 2 个函数:一个函数强制 ssl (force.ssl),一个函数 (no.ssl) 将页面作为 http 提供。

Route::filter('force.ssl', function()
{
if( ! Request::secure() && App::environment() !== 'local')
{
return Redirect::secure(Request::getRequestUri());
}
});

Route::filter('no.ssl', function()
{
if( Request::secure())
{
return Redirect::to(Request::path(), 302, array(), false);
}
});

我在 routes.php 中添加了以下路线。

Route::when('checkout/getpaymentpage/*', 'force.ssl');
Route::when('/*', 'no.ssl');

结帐页面被重定向到 HTTPS 页面,但是,如果用户随后决定通过单击导航栏中的 link 导航到我网站上的另一个页面,则下一页也是作为 HTTPS 页面而不是 HTTP 页面提供服务。即使我明确添加了一个路由以将所有其他页面显示为非 HTTP (no.ssl)。

我不确定我做错了什么?如何确保只有我的结帐页面将作为 HTTPS 提供?

你为什么不直接让你的整个 站点成为 HTTPS?

您将从 Google 获得免费的 SEO 提升:http://googlewebmastercentral.blogspot.com.au/2014/08/https-as-ranking-signal.html

事实上,服务器开销不会有任何实际变化。

否则,您需要做很多工作才能反对当前趋势,使整个网络 https...