如果HTTPS激活,Laravel请求HTTP [英] Laravel request HTTP if HTTPS activated

查看:272
本文介绍了如果HTTPS激活,Laravel请求HTTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个问题,在大多数页面上,我们需要用户使用SSL。所以我们用下面的代码来强制用户进入SSL模式。

  //安全应用程序路由
Route :: filter('force.ssl',function()
{
if(!Request :: secure())
{
return Redirect :: secure Request :: path());
}

});

然而,在两个特定的页面中,用户必须处于http模式(外部服务器不接受https请求)。这同样的逻辑怎么能够反向应用?我假设这样的事情,但重定向不安全?

  //安全应用程序路由
Route :: filter('force。函数()
{
if(Request :: secure())
{
return Redirect :: unsecure(Request :: path());
}

});


解决方案

尝试重定向::至> $ secure 标记设置为 false

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

Redirect :: secure 调用 Redirect :: to 并将最后一个参数设置为 true


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

});

解决方案

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激活,Laravel请求HTTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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