Laravel request HTTP if HTTPS activated

2019-06-07 16:54发布

问题:

So I am having an issue where on most pages we need the user to be on SSL. So we have the following code with a route to force a user to go into SSL mode.

//secure app route
Route::filter('force.ssl', function()
{
    if( ! Request::secure())
    {
        return Redirect::secure(Request::path());
    }

});

This works perfectly however on two specific pages the user HAS to be in http mode (issue with external server not accepting https requests). How can this same logic be applied in reverse? I assume something like this but Redirect unsecure?

//secure app route
Route::filter('force.nossl', function()
{
    if(Request::secure())
    {
        return Redirect::unsecure(Request::path());
    }

});

回答1:

Try Redirect::to with the $secure flag set to false

return Redirect::to(Request::path(), 302, array(), false);

Redirect::secure is just a shortcut that calls Redirect::to with the last parameter set to true