【问题标题】:Laravel redirect Intended not working on ProductionLaravel 重定向不适用于生产
【发布时间】:2018-02-28 09:29:37
【问题描述】:

以下处理身份验证后我的 Laravel 应用程序上的重定向:

protected function sendLoginResponse(Request $request)
{
    $request->session()->regenerate();

    $this->clearLoginAttempts($request);

    //dd(redirect()->intended());
    return $this->authenticated($request, $this->guard()->user())
        ?: redirect()->intended($this->redirectPath());
}

这在我的本地机器上运行良好,但在运行 Elastic Beanstalk 的生产服务器上却不行。

我的代码中的dd() 在两个环境中都显示了正确的路径,但在生产中它重定向到url /。为什么?

【问题讨论】:

    标签: laravel redirect amazon-elastic-beanstalk


    【解决方案1】:

    这可能是因为您使用的是负载平衡的 Amazon 服务器。 负载均衡是这样工作的:客户端使用 HTTPS 连接到负载均衡域,但负载均衡器本身将 HTTP 中的请求转发到实际的服务器。这意味着服务器始终将请求的 URL 视为 HTTP,而不是 HTTPS。

    我画了一张图来进一步解释我的观点:

    【讨论】:

      【解决方案2】:

      您可以创建一个辅助函数来从会话中获取预期的 url

      function intendedUrl($default = null)
      {
        $default = $default ?: route('pages.home');//default route
        return session()->pull('url.intended', $default);
      }
      

      【讨论】:

      • 试过了,在生产环境中不起作用,虽然它在我的本地环境中起作用......
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-14
      • 2011-09-08
      • 2019-05-19
      • 2018-11-16
      • 2020-04-19
      • 2018-03-06
      • 1970-01-01
      相关资源
      最近更新 更多