我今天正在编写一些代码并发送了一个 Redirect::route()
。它没有像往常一样重定向到 base_url/route,而是像这样复制 base_url:
http://myurl.dev/http://myurl.dev/myroute
我觉得我做错了什么,所以我回去尝试找出问题所在。我最终用一个新的 vhost 开始了一个新项目,并将这一小段代码放在 app/routes.php 中:
Route::get(
'test1',
[
'as' => 'test1',
function () {
return Redirect::route('test2');
}
]
);
Route::get(
'test2',
[
'as' => 'test2',
function () {
return 'test2hello';
}
]
);
当我打开 http://myurl.dev/test1在浏览器中,它不只是显示“test2hello”,而是抛出了 http not found 错误,因为 http://myurl.dev/http://myurl.dev/test2没找到。这只发生在 Redirect::route()
上,它在 Redirect::to()
上按预期工作。它也只发生在虚拟主机上;如果我转到 localhost/myurl/public/test1,Redirect::route()
会按预期工作。有什么想法吗?
更新:
有人要求我设置虚拟主机。我在 Mac OSX 10.8.5 上使用内置的 Apache。我取消了 /etc/apache2/httpd.conf 中 httpd-vhosts.conf 包含行的注释。我在 /etc/apache2/extra/httpd-vhosts.conf 中添加了一些虚拟主机,这是一个:
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents/example_blog/public"
ServerName example_blog.local
</VirtualHost>
和/etc/hosts中的相应行:
127.0.0.1 example_blog.local
并重新启动 Apache。该文件夹名为 example_blog.local
。
最佳答案
问题似乎与未通过 FILTER_VALID_URL 的 URL 中的下划线有关:
https://github.com/laravel/framework/issues/2511
(不归功于我的答案,因为我只是整理这个以帮助其他人寻找解决方案)
关于php - Laravel Redirect::route() 在 vhost 上访问错误的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19390453/