Laravel Redirect All Requests To NON-HTTPS

2019-07-04 00:09发布

There are lots of questions asking how to make a Laravel request HTTPS, but how do you make it NON HTTPS. I'd like to make sure all the pages that are not the order page, are not SSL. Basically the opposite of Redirect::secure.

    //in a filter

    if( Request::path() != ORDER_PAGE && Request::secure()){
    //do the opposite of this:
    return Redirect::secure(Request::path());
    }

标签: php ssl laravel
2条回答
Emotional °昔
2楼-- · 2019-07-04 00:51

try this //in a filter

if( Request::path() != ORDER_PAGE && Request::secure()){
//do the opposite of this:
return Redirect::to(Request::path());
}

May be this will help you.

查看更多
放荡不羁爱自由
3楼-- · 2019-07-04 01:06

I solved it with a filter that I map to all routes I need to make non SSL

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

Example for a route with non SSL only

Route::get('/your_no_ssl_url', array(
    'before' => 'prevent.ssl',
    'uses'   => 'yourController@method',
));

If you open https://example.app/your_no_ssl_url you will be redirected to http://example.app/your_no_ssl_url

查看更多
登录 后发表回答