Accepting an encoded URL in a Laravel 4 route

爱⌒轻易说出口 提交于 2019-12-06 02:55:25

Give this regex a go, it will match any characters...

Route::get('add/{encoded_url}', function($encoded_url)
{
    return 'The URL is: '.rawurldecode($encoded_url);
})->where('encoded_url', '.*');

Phill's answer is correct but I also had to make a change in my apache settings to get this working.

I had to add the following to my httpd.conf file:

AllowEncodedSlashes NoDecode

You'll need this if your are seeing an Apache 404 not found page as opposed to a Laravel NotFoundHttpException error page.

Pretty obvious explanation, but without this Apache was decoding the encoded slashes so that

http://localhost/add/http%2F%2Fwww.google.co.uk

was being routed to

http://localhost/add/http://www.google.co.uk

urlencoded slashes do not work in Laravel due to what I consider a bug.

https://github.com/laravel/framework/pull/4323

This pull request will resolve that bug.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!