I was working on some code today and sent a Redirect::route()
. Instead of redirecting to the base_url/route as usual, it duplicated the base_url like this:
http://myurl.dev/http://myurl.dev/myroute
I figured I did something wrong, so I went back and tried to isolate the problem. I ended up starting a new project with a new vhost and putting this tiny bit of code in app/routes.php:
Route::get(
'test1',
[
'as' => 'test1',
function () {
return Redirect::route('test2');
}
]
);
Route::get(
'test2',
[
'as' => 'test2',
function () {
return 'test2hello';
}
]
);
When I open http://myurl.dev/test1 in a browser, instead of just showing "test2hello" it threw and http not found error because http://myurl.dev/http://myurl.dev/test2 was not found. This only happens on Redirect::route()
, it works as expected on Redirect::to()
. It also only happens on vhosts; Redirect::route()
works as expected if I go to localhost/myurl/public/test1. Any ideas?
UPDATE:
I was asked for my vhost setup. I am on Mac OSX 10.8.5 and am using the built-in Apache. I've uncommented the httpd-vhosts.conf include line in /etc/apache2/httpd.conf. I've added a few vhosts to /etc/apache2/extra/httpd-vhosts.conf, here's one:
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents/example_blog/public"
ServerName example_blog.local
</VirtualHost>
and the corresponding line in /etc/hosts:
127.0.0.1 example_blog.local
and restarted Apache. The folder is named example_blog.local
.
Problem appears to be related to having an underscore in the URL, which does not pass FILTER_VALID_URL:
https://github.com/laravel/framework/issues/2511
(no credit to me for the answer as I'm just tidying up this to help others searching for solutions to this)