Framework: Router caching: navigate to url with trailing '/' gets different result from non cached router

Created on 5 Mar 2020  Â·  14Comments  Â·  Source: laravel/framework

  • Laravel Version: 7.0.4 and 7.0.5
  • PHP Version: 7.4.2 // 7.3

Steps To Reproduce:

  1. start new laravel site

  2. Remove default Closure routes

  3. Adding two routes that simply echoes their content ( 2nd overrides 1st, they are same)

Route::get('/test','TestController@withoutTrailing');  //echo withoutTrailingRoute
Route::get('/test/','TestController@withTrailing');  //echo withTrailingRoute

$ php artisan:serve
Navigate to "/test" and "/test/" both giving same result "withTrailingRoute"

  1. Cache routes
    $ php artisan optimize (or route:cache)

Navigate to "/test" giving result "withTrailingRoute"
Navigate to "/test/" throws ResourceNotFoundException

Quick workaround

add middleware with earliest start //Before checkMaintenanceMode for ex.
$request->server->set('REQUEST_URI', rtrim($request->server->get('REQUEST_URI'), '/'));

bug

Most helpful comment

Can confirm. Still relevant with 7.2.0.

All 14 comments

I have similar issue too.
My index route will return 404 when route in cached mode
php Route::get('/', 'DashboardController@index')->name('index');

php php artisan route:list confirmed that this single particular route is not registered if route is being cached.

We're investigating this

7.0.7 seems to fix this even though 7.0.8 change-log is referring to this bug

@rognales
i dont think so

We've pushed a fix that will get tagged tomorrow. Thanks for reporting.

Hi @driesvints ,
Are you referring to the release laravel 7.1.0,
I have just checked it is still not working

7.1.0 resolved this problem for me. Make sure to clear and rebuild your route cache.

On Mar 11, 2020, at 2:19 AM, Manash Sonowal notifications@github.com wrote:


Hi @driesvints ,
Are you referring to the release laravel 7.1.0,
I have just checked it is still not working

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

@msonowal are you sure? Because that definitely should have fixed it.

I have the same issue, even with 7.1.0.

Route::get('/test','TestController@show');

Using example.com/test works, using example.com/test/ results in a 404.

Disabling route cache fixes the issue.

@msonowal are you sure? Because that definitely should have fixed it.

Yes I am sure,
I have cleared cache and recached

@driesvints I'd like to confirm that the bug still occurs. Could you reopen the issue?

ping @GrahamCampbell @driesvints any update on this?

Open up a new issue with exact steps to reproduce please.

Can confirm. Still relevant with 7.2.0.

Was this page helpful?
0 / 5 - 0 ratings