It is common to create laravel projects in subfolders, and perform an access configuration by subdomains, something similar to: https://mydomain.com/aliasdomain
, generally, this has been supported and at the time of caching the routes hasn't been generated a type of conflict, however, in laravel 7 this has generated a mistake in the routes that are specified as:
Route::get('/', '.....')
A solution implemented in a project to solve this problem with the route cache was:
- Create a middleware with the following validation:
class RouteCache
{
public function handle(Request $request, Closure $next)
{
if ($request->path() === '/') {
$newURI = $request->server->get('REQUEST_URI') . 'index.php';
$request->server->set('REQUEST_URI', $newURI);
}
return $next($request);
}
}
- Add the middleware to the Kernel file in the middleware array:
protected $middleware = [
....,
\App\Http\Middleware\RouteCache::class,
];
With this, what is achieved is that if a route /
is declared within the project, the middleware validates when trying to access it and overwrites the REQUEST_URI
value that the request carries by adding index.php
(this will continue being transparent to the end user)
Top comments (0)