Ok I know whats the problem. The current directory structure will not work in real life.
In a web application / website, it is important to distinguish between the public and non-public areas.
The public/ directory serves your application and will therefore also be directly accessible by all browsers, search engines and API clients. All other folders are not public and must not be accessible online. This can be done by defining the public folder in Apache as DocumentRoot of your app / website.
I have written about this this topic in this Slim 4 Turorial.
The “solution” is quite simple:
- Move the file
index.phpfile intopublic/directory (maybe fix some paths to the autoloader) - Move your public “assets” (js, css etc) directory into the
public/directory too - In your prod env: Define the public/ path as your
DocumentRoot - Create a file:
public/.htaccesswith this content:
# Redirect to front controller
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
- Create a second
.htaccessfile above thepublic/directory with this content:
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
The second .htaccess file is only importand for your local development environment, but can be deployed too.