Root Path works, Subpath Not found on the remote server

Hi,
I developed several slim applications (v3) and installed them on different servers, windows, linux (different release). I never had problems.

Now I installed on a new Ubuntu 18 server, Apache2, PHP 7.2 and I have problem with subfolder path.

This works:

$app->get('/', function (Request $request,  Response $response, $args) {
return $response->withStatus(400)->write('DEMO :: Bad Request');
});

This not Works, Error 404

$app->get('/hello', function (Request $request,  Response $response, $args) {
return $response->withStatus(400)->write('DEMO :: hello');});

I have a subfolder inside apache 2 root folder:
root-folder: /var/www/html
application-folder: /var/www/html/mgdlab-webgis/rest

this is my .htaccess file:

RewriteEngine On
Header Set Access-Control-Allow-Origin "*"
Header Set Access-Control-Allow-Headers "Accept,Content-Type,Access-Control-Allow-Headers"
Header Set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

Could you please help me to understand the problem? I read several posts similat to my issue but I can’t solve.

Thanks in advance

Luca

The PSR-7 response object is immutable, but the response body stream is not immutable.
So try this instead:

$app->get('/', function (Request $request,  Response $response, $args) {
    $response->getBody()->write('DEMO :: Bad Request');
    
    return $response->withStatus(400);
});

If you run Slim 3 (and 4) in a sub-directory you need two .htaccess files.

The first file in your project root directory:

RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]

The second file where your index.php files is stored, e.g. under public/:

# Redirect to front controller
RewriteEngine On
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]