2

我今天正在编写一些代码并发送了一个Redirect::route(). 它没有像往常一样重定向到 base_url/route,而是像这样复制了 base_url:

http://myurl.dev/http://myurl.dev/myroute

我认为我做错了什么,所以我回去尝试找出问题所在。我最终用一个新的虚拟主机开始了一个新项目,并将这段代码放在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 未找到错误,因为http://myurl.dev/http://myurl.dev/test2不是成立。这只发生在 上Redirect::route(),它按预期工作Redirect::to()。它也只发生在虚拟主机上;Redirect::route()如果我转到 localhost/myurl/public/test1,则按预期工作。有任何想法吗?


更新:

我被问到我的虚拟主机设置。我在 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.

4

2 回答 2

5

问题似乎与 URL 中有一个下划线有关,它没有通过 FILTER_VALID_URL:

https://github.com/laravel/framework/issues/2511

(我的答案不值得称赞,因为我只是整理一下以帮助其他人寻找解决方案)

于 2013-12-28T04:31:27.463 回答
1

试试这个方法:

Route::get(
    'test1',
    [
        'as' => 'test1',
        function () {
            return Response::make('', 302)->header('Location', route('test2'));
        }
    ]
);

Route::get(
    'test2',
    [
        'as' => 'test2',
        function () {
            return 'test2hello';
        }
    ]
);

如您所见,我们使用响应类,重定向本身使用它来发送标头位置:)

于 2014-02-18T23:37:13.513 回答