1
votes

I just finished the installation guide of setting up a php slim app. Everything is working fine except when the user specifies an url that doesn't exist in the app, he is not getting redirected to the index.php.

I think it has something to do with the index.php located in the public directory instead of the project root directory.

My file structure looks as follows:

-public
----.htaccess
----index.php
-src
-vendor
----composer
----fig
----nikic
----psr
----ralouphie
----slim

And my .htaccess file contains the following:

RewriteEngine On

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

Allow from all

By the way when I specify a non existing route I get a Slim\Exception\HttpNotFoundException exeption. Which makes sense since the route does not exist. But it should redirect to the index.php

1

1 Answers

0
votes

I read the documentation and there is specified, that slim has a notFound method, which is invoked when there is an error 404, so may it will help you:

$app = new \Slim\Slim();
$app->notFound(function () use ($app) {
    $app->render('index.html');
});