Irfan DANISH
Irfan DANISH

Reputation: 8489

Laravel: URLs with encoded characters generate 404 exception

I am working on a laravel 4.2 based project and I am facing a strange issue.

Problem

I have a URL e.g, http://example.com/events/eventname/registration#get_register

above URL works perfectly but when special characters are encoded then I ended up with following URL

http://example.com/events/eventname/registration%23get_register

and this encoded URL gives me laravel's 404 exception.

Details:

I noticed this issue when I sent my project link to a colleague via Skype and iOS version of Skype encode URLs in message. So when my colleague opened that link from Skype he got exception.

Update

My route code

//Free Registration
Route::any('events/{event_url}/registration', 'MyController@registration_step1');

Upvotes: 0

Views: 1328

Answers (1)

Rob
Rob

Reputation: 12872

The main issue is that hash tags in url's aren't sent to the server. They are used by the browser. So when you use http://example/#hash, the server will only see http://example/. When the hash is encoded with %23, the server does get the full url. If you want laravel's routes to recognize the url with %23 then you should match it and handle it or match it and redirect. For example...

Route::get('events/{event_url}/registration/*', 'MyController@registration_step1');

or...

Route::get('events/{event_url}/registration{hash?}', 'MyController@registration_step1');

depending if you need to capture the parameter or not.

Upvotes: 2

Related Questions