Always get 404 error in Slim Framework when there is no index.php index in the url

I created a hello world Slim test application with instructions here .

When I make this call, I get 404 error:

http://my_server/my_app/hello/John 

On the other hand, when I make this call, it works fine when I get the message "Hello John":

 http://my_server/my_app/index.php/hello/John 

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

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

I forgot to create a .htaccess file like this (after the Slim Framework documentation and in the 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 
+7
source share
4 answers

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

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

If this is at the root of your document, you need to add the path:

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

You can also change .htaccess to the following: (I had a similar problem and this resolved this for me):

.htaccess:

 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L] 
+5
source

If the Jon Lin solution does not work, then your .htaccess file does not work. you can check that my garbage line add for example

 RewriteEngine On RewriteBase /loop/v1/ This is garbage line RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^ index.php [QSA,L] 

this will result in a 503 error if .htaccess is working fine, otherwise you won't get any errors.

if you have not received any errors, select Allow none to Allow all in the Directory section of the apache conf or Httpd.conf file

+1
source

This resource explains everything we need to configure in order to use slim on Ubuntu (this helped me solve my 404 problem):

To summarize, there are two things to configure:

  • Activate mod_rewrite a2enmod rewrite
  • Change Apache configuration file (change AllowOverride None to AllowOverride All for the document root)

Remember to restart apache2 after changes: service apache2 restart

How to install and configure Slim Framework on Ubuntu 14.04

-one
source

All Articles