Problem with routes inside a folder


#1

I have an app with the following structure:

App/
|— app/
    |— config
    |— controllers
    |— middlewares
    |— routes
         |— routes.php
    |— views
    |— app.php
    |— autoload.php
|— public/
    |—.htaccess
    |— 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';
$app->run();

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

<?php
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/:

<?php

/*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
    </Directory>
</VirtualHost>

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.


#2

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


#3

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