Laravel将所有请求重定向到NON-HTTPS [英] Laravel Redirect All Requests To NON-HTTPS

查看:130
本文介绍了Laravel将所有请求重定向到NON-HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多问题询问如何使Laravel请求HTTPS,但如何使它成为 NON HTTPS .我想确保所有不是订购页面的页面都不是SSL.基本上与Redirect :: secure相反.

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());
    }

推荐答案

我用一个过滤器解决了这个问题,该过滤器映射到我需要建立非SSL的所有路由

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);
    }
});

仅非SSL路由的示例

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

如果打开https://example.app/your_no_ssl_url,您将被重定向到http://example.app/your_no_ssl_url

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

这篇关于Laravel将所有请求重定向到NON-HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆