You can't remove the second route $app->get('/')
as it is the Home default route and it is quite normal to get a 404 because $app->get('/:name', function ($name) {})
is expecting a callback function's argument 'name'
that is missing.
Are you trying the following:
http://localhost/mysite/ --- Outputs Hello World
http://localhost/mysite/marcosh --- Outputs a 404 ??
If this is the case then as a77icus5 suggested we may need to look into your htacess file and what is the project directory structure...
I have a fresh Slim Skeleton install and I thought I'd share my configuration with you...
My Web project directory is as follow :
Webroot
-htaccess
- public
-- htaccess
-- assets
--- js
--- css
- templates
- app
- vendor
-- Slim
-- Twig
In the first .htaccess
located in the project root directory I added :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Here public
matches the name of the app public folder
Then in the .htaccess
located in the public folder I added :
<IfModule mod_php5.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
Then in SLIM -> Environment.php (line 142 - Virtual Path ) and try to edit as follow :
// Virtual path
// $env['PATH_INFO'] = substr_replace($requestUri, '', 0, strlen($physicalPath)); // <-- Remove physical path
$env['PATH_INFO'] = str_replace(str_replace('/public', "", dirname($_SERVER['PHP_SELF'])), '', "/".$requestUri); // remove public from URI
$env['PATH_INFO'] = str_replace('?' . $queryString, '', $env['PATH_INFO']); // <-- Remove query string
$env['PATH_INFO'] = '/' . ltrim($env['PATH_INFO'], '/'); // <-- Ensure leading slash