I created a clean new project using odan/slim4-skeleton.
However, it is not located in the DocumentRoot /var/www/html but in the subfolder …/slim.
Therefore, in container.php, directly after instantiating $app, I executed:
$app->setBasePath('/slim')
But even with this BasePath set, I still get a 404 error.
Workaround:
By commenting out the BasePathMiddleware in Middleware.php ($app->add(BasePathMiddleware::class)), the BasePath set in the container is no longer overwritten, and everything works as expected.
My Apache config:
DocumentRoot /var/www/html
# Slim Subfolder
Alias /slim /var/www/html/slim-api/public
public/.htaccess:
RewriteEngine On
RewriteBase /slim
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
The application is explicitly accessed via the subfolder:
https://domain/slim
There might also be a better or more automated approach in the skeleton. One option, for example, would be to check in Middleware.php whether another BasePath has already been set and, if so, ignore the BasePathMiddleware.
I created a clean new project using odan/slim4-skeleton.
However, it is not located in the DocumentRoot
/var/www/htmlbut in the subfolder…/slim.Therefore, in
container.php, directly after instantiating$app, I executed:$app->setBasePath('/slim')But even with this BasePath set, I still get a 404 error.
Workaround:
By commenting out the
BasePathMiddlewareinMiddleware.php($app->add(BasePathMiddleware::class)), the BasePath set in the container is no longer overwritten, and everything works as expected.My Apache config:
public/.htaccess:
The application is explicitly accessed via the subfolder:
https://domain/slimThere might also be a better or more automated approach in the skeleton. One option, for example, would be to check in
Middleware.phpwhether another BasePath has already been set and, if so, ignore theBasePathMiddleware.