Question

I am trying to implement a talking url scheme in laravel4 for SEO purposes.

What I have in my routes.php is this:

Route::get('{url}', array('as' => 'prettyurl', function($url) .........

which works for URLs such as

mywebsite.com/this-is-my-fancy-url-about-foo
mywebsite.com/bars

but doesn't for those such as

mywebsite.com/bars/this-is-my-fancy-url-about-foo

it seems that laravel splits the URL according to / before parring it to individual routes.

I could do something like

Route::get('{prefix}/{url?}', array('as' => 'prettyurl', function($prefix, $url) .........

but it seems a little contrived.

Any ideas?

Was it helpful?

Solution

You can use regular expressions to make it catch everything (including the slashes).

Route::get('{url}', ['as' => 'prettyurl', function($url)
{

})->where('url', '.*');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top