Problem with routes inside a folder


I have an app with the following structure:

|— app/
    |— config
    |— controllers
    |— middlewares
    |— routes
         |— routes.php
    |— views
    |— app.php
    |— autoload.php
|— public/
    |— index.php
|— vendor/

Ok, in the .htaccess on the /public folder contain the following (from the Slim docs):

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

And the index.php on the /public folder contain the following:

define('BASE_ROOT',dirname(__DIR__) . '/');
require_once BASE_ROOT.'app/app.php';

So, we go to the app/app.php file:

require BASE_ROOT.'app/autoload.php';

$app = new \Slim\App(["settings" => App\Config\Config::$config]); 

$container = $app->getContainer(); 
$container['view'] = function($container) {
  /*Set some configurations and environment vars*/

require BASE_ROOT.'app/routes/routes.php';

And finally, in the routes.php inside on app/routes/:


$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
  $name = $args['name'];
  $response->getBody()->write("Hello, $name");

I’ve put the ‘hello world’ route to simplify things, but the problem is that with any route registered in routes.php I receive 404 code…

I’m using apache server and the configuration on vhost is the following:

<VirtualHost *:80>
    DocumentRoot "C:\Users\FranciscoSalazar\Desktop\PHP-SLIM\App\public"
    ServerName medo
    <Directory C:\Users\FranciscoSalazar\Desktop\PHP-SLIM\App\public>
        DirectoryIndex index.php
        AllowOverride All
        Require all granted

I have read several similar cases but not the same, and some indicate that the problem is in the .htaccess files, but I have not been able to find the solution yet.
If someone knows the answer or can guide me, I will appreciate it very much.


Can you please try this Slim 3 Hello World application and tell us if it works under windows and apache?


@odan, yes. It’s works under windows 10 and apache 2.4.