framework: Trailing Slash Bug For Cached Index Route
- Laravel Version: 7.2.2
- PHP Version: 7.2.5
Update:
- Laravel Version: 7.3
- PHP Version: 7.3.15
Description:
I am using this route:
Route::get('/', 'IndexController@index')->name('index');
Which does not work when I run php artisan route:cache
Error that gets outputed: The GET method is not supported for this route. Supported methods: HEAD.
I located this file: Illuminate/Routing/CompiledRouteCollection.php
Inside that file it uses this function that removes trailing slashes from a routes URI:
protected function requestWithoutTrailingSlash(Request $request)
{
$trimmedRequest = Request::createFromBase($request);
$parts = explode('?', $request->server->get('REQUEST_URI'), 2);
$trimmedRequest->server->set(
'REQUEST_URI', rtrim($parts[0], '/').(isset($parts[1]) ? '?'.$parts[1] : '')
);
return $trimmedRequest;
}
If I were to remove the / from rtrim($parts[0], '/')
my index route now starts working like normal.
Steps To Reproduce:
Create a route inside web.php which has just a slash as the URI.
Cache the routes by using php artisan route:cache
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 16 (10 by maintainers)
We don’t support Laravel projects in sub directories, sorry.
Hi I know this issue is closed, and I understand you guys do not want to serve Laravel in a subdirectory due to security concern. However, in our current PROD setup, we have multiple apps (built by different teams, some built in laravel and some aren’t) that sit behind an application load balancer (ALB). ALB will route traffic to appropriate app based on URL (e.g. domain/app1 and domain/app2). So technically, we are not violating the no-serving-Laravel-application-out-of-a subdirectory-of-the-web-directory-on-web-server rule. I know this is a very particular setup, but I can’t imagine we are the only one doing this. With this change, we are now pretty tightly cornered into either being stuck on an older Laravel version for our apps, or finding some way to hack things and make it work (e.g. overriding framework class). Is it not possible for you guys to enforce the said rule in a different way? Or can you provide an opt-out settings?
@hulkur it doesn’t. Please don’t place your laravel app in a subdirectory.