Reputation: 3541
I've built a Slim PHP app and published it on my webserver.
The routes are only available if I browse directly via the index.php page
for example example.com/index.php/login
and /index.php/signup
both render the expected views
however if I omit index.php and browse to `example.com/login' or 'example.com/signup' I get a 404
My .htaccess
file is located in the same directory as index.php
public/
├── .htaccess
├── index.php
the public
folder is configured as the DocumentRoot /var/www/example.com/public
in apache
My .htaccess
file contains the following:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Any suggestions how to fix my routing?
Upvotes: 3
Views: 8080
Reputation: 2238
Slim recommends using these rules for Apache. (.htaccess)
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
Rembember you have to set the AllowOverride directive to "All" in the Apache config and make sure that "/public" is your root virtual directory.
Upvotes: 6