Skip to content

Error 404 despite setBasePath and project in subfolder #137

@mic60-code

Description

@mic60-code

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions