antur123 antur123 - 8 months ago 47
PHP Question

Always get 404 error in Slim Framework when omitting index.php in URL

I created a test hello world Slim app following instructions here.

When I make this call I get a 404 error:


In the other hand, when I make this call it works grand as I get a "Hello John" message:


But, of course, I don't want index.php in my URLs... What can be wrong?

======= EDIT =======

I forgot creating .htaccess file like this (following Slim Framework documentation, and in same directory as index.php):

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Now I get this error:

/physical_path_to_my_files/index.php was not found on this server


If your htaccess file is in your /my_app directory, change your rules to:

RewriteEngine On

RewriteBase /my_app/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

If it's in your document root, you need to append the path:

RewriteRule ^ /my_app/index.php [QSA,L]