【问题标题】:Redirecting to external url, resulting in 404 laravel 5.8重定向到外部 url,导致 404 laravel 5.8
【发布时间】:2019-11-10 19:13:57
【问题描述】:

我以为这会很简单,但我很难过。

我的站点导航上有一个链接,该链接指向一个 aws pdf 文件并且工作正常。我正在尝试创建一个用户可以输入并重定向到该文件的命名路由,但我得到了 404。

我试过了:

Route::get('Documents', function () {

    return redirect()->away('http://s3.aws/documents.pdf');

});

Route::get('Documents', function () {

    return redirect()->to('http://s3.aws/documents.pdf');

});

    Route::get('Documents', function () {

    return redirect('http://s3.aws/documents.pdf');

});

当我访问 www.mysite.com/Documents 时,它们都会导致 404

有什么想法吗?

【问题讨论】:

  • 你确定你有正确的 aws 链接吗?
  • 是的,我将它从工作链接复制到了路线
  • 当你输入 php artisan route:list 时知道错误是什么会很有用,好像 Laravel 无法列出路线,更有可能它不会在你请求站点时注册它们,所以你得到这些 404
  • 好点。这是 routes.php 中的语法错误,然后是 bootstrap/cache/compiled.php 中的 5 个错误的堆栈跟踪

标签: php html laravel routes


【解决方案1】:

随便用

return Redirect::to($url);

在此处阅读有关laravel redirects 的更多信息。

【讨论】:

  • 我也把这个也放进去了,但还是得到了 404
  • 我在这里测试了它并且它正在工作。无法重现您的错误。
  • 这是我的测试:Route::get('/test', function(){return \Redirect::to('https://google.com');}); 这是网址,如果你想看:mateusjunges.com/test
  • 嗯。我曾经也有一个名为 Documents 的站点的公共目录,但我重命名了它。会不会导致错误?
  • 你发布的测试也得到了 404。这就像它不会让我在外部重定向。我的路由文件中有另一个重定向到一个工作正常的内部 url,我的结构相同
猜你喜欢
  • 1970-01-01
  • 2021-12-23
  • 2015-04-22
  • 2021-05-08
  • 2014-02-15
  • 2017-12-11
  • 2012-01-10
  • 2012-08-02
  • 1970-01-01
相关资源
最近更新 更多