【问题标题】:Laravel Redirect All Requests To NON-HTTPSLaravel 将所有请求重定向到非 HTTPS
【发布时间】:2014-11-17 06:34:09
【问题描述】:

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

    //in a filter

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

【问题讨论】:

  • 这可能会迟到,但它可能会帮助未来的访问者。看看this answer

标签: php ssl laravel


【解决方案1】:

我用一个过滤器解决了这个问题,我映射到我需要制作非 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

【讨论】:

    【解决方案2】:

    试试这个 //在过滤器中

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

    也许这会对你有所帮助。

    【讨论】:

    • 感谢您的回复。但是我试过了,它仍然重定向到 https。它会创建一个重定向循环。
    猜你喜欢
    • 2013-11-26
    • 2013-04-06
    • 1970-01-01
    • 1970-01-01
    • 2016-10-23
    • 2014-02-13
    • 2016-05-13
    • 2014-06-30
    • 2018-09-15
    相关资源
    最近更新 更多