-1

I am working on one site where I need to show 404 pages when someone adds double slash in URL.

I have written logic to check REQUEST_URI and if there is double slash then I am showing 404 pages...

But when I add double slash in URL it shows single slash in REQUEST_URI but in URL, it is double slash...

here I attached a screenshot for the same issue.

For Example: if i enter www.example.com//check -> then its is coming as /check in REQUEST_URI but i want it should come as //check

Site is hosted in AWS cloud load balancer (ELB). in local setting its working proeper but in production its creating issue.

Can someone help me how can I prevent this?

enter image description here

Jigar
  • 3,055
  • 1
  • 32
  • 51
  • An extra `"/"` in URL breaks the `URL`. That value must be encoded if you want to put it in a query string. – Andrei Lupuleasa Apr 24 '19 at 11:11
  • I am not putting that slash in URL. I just want to add logic if someone manipulates URL in the browser it should not show that page it should show 404 page – Jigar Apr 24 '19 at 11:13
  • 1
    for example, if you open any landing page from my site and you add extra slash in url then it should not show that page @AndreiLupuleasa – Jigar Apr 24 '19 at 11:14
  • there are solutions for what you are trying to achieve: https://stackoverflow.com/questions/29479409/redirect-to-homepage-if-route-doesnt-exist-in-laravel-5 – Andrei Lupuleasa Apr 24 '19 at 11:15
  • @AndreiLupuleasa this is not working I have tried before. – Jigar Apr 24 '19 at 11:24

1 Answers1

0

Laravel 5.5.5 introduced a new feature in routing, called Route::fallback(). Basically, if no route is matched, then fallback function is a way to override default 404 page and introduce additional logic. Here’s how it works.

Route::fallback(function() {
    return 'Hm, why did you land here somehow?';
});
Andrei Lupuleasa
  • 2,677
  • 3
  • 14
  • 32
  • actually, we don't have routes for all page some routes are landing page and we are catching all routes using Route::get('{catchall}', 'MyController@suburl')->where('catchall', '.*'); so this solution will not work – Jigar Apr 24 '19 at 11:30
  • I think we need to fix this on server level that why the server is not returning double slash from url – Jigar Apr 24 '19 at 11:31
  • its also returning same /check – Jigar Apr 24 '19 at 11:37