简体   繁体   English

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

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

I'd like to serve the checkout page on my website as “HTTPS”, but all the other pages on my site need to stay “HTTP”. 我想在我的网站上以“ HTTPS”作为结帐页面,但我网站上的所有其他页面都必须保持“ HTTP”。 My SSL certificate is correctly installed, and the SSL routing is working fine on my server. 我的SSL证书已正确安装,并且SSL路由在我的服务器上工作正常。

I've added 2 functions in filters.php: one functions to force ssl (force.ssl), and one function (no.ssl) to serve pages as http. 我在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);
}
});

I added the following routes in routes.php. 我在routes.php中添加了以下路由。

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

The checkout page is being redirected to an HTTPS page, however, if the user then decides to navigate to another page on my site by clicking on a link in the navigation bar, the next page is also being served as an HTTPS page and not as an HTTP page. 结帐页面将重定向到HTTPS页面,但是,如果用户随后决定通过单击导航栏中的链接来导航到我网站上的另一页面,则下一页也将用作HTTPS页面,而不是HTTP页面。 Even though I explicitly added a route to show all other pages as non HTTP (no.ssl). 即使我显式添加了一条路由,以将所有其他页面显示为非HTTP(no.ssl)。

I'm not sure what I'm doing wrong here? 我不确定我在做什么错吗? How can I make sure only my checkout page will be served as HTTPS? 如何确保仅将我的结帐页面用作HTTPS?

Why dont you just make your whole site HTTPS? 您为什么不只对整个站点进行HTTPS?

You'll get a free SEO boost from Google: http://googlewebmastercentral.blogspot.com.au/2014/08/https-as-ranking-signal.html 您将获得Google的免费SEO提升: http : //googlewebmastercentral.blogspot.com.au/2014/08/https-as-ranking-signal.html

And the reality is it'll have no real changes in server overhead. 事实是,服务器开销不会有任何实际变化。

Otherwise your doing a lot of work to go against the current trend to make the whole web https... 否则,您需要做很多工作来当前趋势背道而驰,以使整个Web成为https ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM