Laravel request HTTP if HTTPS activated

半世苍凉 提交于 2019-12-08 04:07:04

问题


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



来源:https://stackoverflow.com/questions/26875852/laravel-request-http-if-https-activated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!