php - Laravel Redirect::route() 在 vhost 上访问错误的 url

标签 php laravel laravel-4 vhosts

我今天正在编写一些代码并发送了一个 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.confhttpd-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/

相关文章:

php - 将 android 连接到队列应用程序的数据库

php - Javascript/HTML 表单字段命名问题

laravel - artisan 不在 laravel 5.2 中工作返回 [ErrorException]

php - 如何在 blade.php 中获取输入值

php - 类 Carbon\Carbon 未找到

php - 需要有关构建无状态 Web 应用程序的信息

php - 拉维尔 5 : differentiate if new row inserted in DB

database - 在 laravel 4 中克隆数据库或运行 sql dump

php - 在 Laravel 4 中使用数据库结果填充下拉菜单

php - 如果文本太大,如何重新调整输入