2

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.

Laurence
  • 58,936
  • 21
  • 171
  • 212
Mike Funk
  • 373
  • 6
  • 22
  • 1
    How did you set your vhosts? Can you post the configuration? I tested your routes in my laravel installation and I didn't get any problem. I think it is a issue about rewrite mode or vhost is not set correctly in your project. – Darwing Oct 15 '13 at 22:26
  • @Darwing I've added my vhost setup – Mike Funk Oct 18 '13 at 18:17
  • I don't know right now if the directive/tag `Directory` is really important but you are missing it in your vhost configuration. In [this tutorial](http://codehappy.daylerees.com/getting-started) you can see an explanation how to set correctly vhost configuration with Laravel. – Darwing Oct 19 '13 at 03:32

2 Answers2

5

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)

markdwhite
  • 2,360
  • 19
  • 24
  • 1
    Well good people, I regret that I too am experiencing this problem. In my case, the domain name has a dash in it. Also, I'm using a Route group that defines possible subdomains in curly braces. I have a route named 'setup' defined as 'settings/{setup}' Redirect:route('setup', array('error' => '1')) is taking me to: http://sub.name.our-site.com/http://{subdomain}.{name}.our-site.com/settings/{setup}?error=1 That is literally the URL it tries to load. Shouldn't hyphens be valid in domain names? – Spencer Williams Jan 30 '14 at 20:39
  • Bless you! I was banging my head against the wall trying to figure this out. – Rob Cozzens Mar 04 '15 at 00:21
1

Try this method :

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

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

as you can see we use Response Class which Redirect itself uses it to send header location :)

Mehdi Maghrouni
  • 1,529
  • 22
  • 23