0

Version Laravel Framework 7.21.0

I am having issue to allow double slash in the url.

Success : http://example.com/api/v1/reference

NotFound Exception : http://example.com//api/v1/reference

How do i allow double slash in my url ?

I managed to allow multiple slash in the url in the previous Version of Laravel : 5.8.16

Azharan
  • 21
  • 6

1 Answers1

1

You can add Middleware

php artisan make:middleware removeSlashes

and add it to $routeMiddleware under App/Http/Middleware

protected $routeMiddleware = [
  'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
   ....
  'removeSlashes' => \App\Http\Middleware\RemoveSlashes::class,        
];

implement code to remove extra slash in RemoveSlashes::class

and call to middleware in your api.php

Route::group(['prefix' => 'v1', 'middleware' => ['RemoveSlashes'....]], function () { 
    Route::GET(.....);

});
Eden Moshe
  • 1,097
  • 1
  • 6
  • 16
  • It does not work, as your prefix is not matched. Look at https://stackoverflow.com/questions/34302687/change-the-get-url-before-laravel-5-1-route-intercepts-it for a solution to actually remove the double slashes – Krapow May 20 '21 at 12:23