简体   繁体   中英

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”. My SSL certificate is correctly installed, and the SSL routing is working fine on my server.

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.

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.

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. Even though I explicitly added a route to show all other pages as non 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?

Why dont you just make your whole site HTTPS?

You'll get a free SEO boost from Google: 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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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