Page Not Found - 404

I am trying to right a basic controller that all requests get redirected through. I have made a simple Slim app that runs in this controller, and I keep getting the dreaded slim ‘Page Not Found’ page. Have gone through a ton of Google searches and none of the answers fix my problem. Finally decided to post in here.

This is my basic Apache Conf, and mod rewrite is on.

RewriteRule ^.* /controller.php [QSA,L]

So everything should be redirected through the controller script in the web root directory.

controller.php looks like this:
require_once( DIR . ‘/config.php’ );
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

 $config = [ 
        'settings' => [
        'displayErrorDetails' => true,
        'addContentLengthHeader' => false,
 $app = new \Slim\App($config);
 $app->get('/test/', function ($request, $resp, $args) {
    return $resp->withStatus(200)->write(print_r($resp, true));


I know this script is getting called because I can do a “print_r($_SERVER); exit;” and see the output. But for some reason my route is not being registered.

What am I doing wrong?

And you’ve tried using the following like the website suggests?

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . controller.php [L]

and then
require_once( DIR . ‘/config.php’ );

I see the two underscores next to DIR aren’t displayed here for some reason, but I assume you have them there

Also, remove the last forwardslash in your route so that it reads

$app->get(’/test’ … instead of $app->get(’/test/’ …

Yes, the last slash I have tried to remove as well. Does not work. The page loads fine, there are no syntax errors. The two underscores don’t show here, but they are there. _ _ DIR _ _.

The rewrite rules you have shown are what I have.

The only thing I can think of is that I am using this as a virtual host. Would that have any impact?

Sorry, friend, i’m not too sure about that. Hopefully someone else can assist further

Actually I just figured it out. I didn’t have the .htaccess file in the document root directory.

Also, it should look like this:

RewriteEngine On
RewriteRule ^ controller.php [QSA,L]

Champion! Well done!

Actually I spoke too soon. This does not work. Something is wrong with how Slim is trying to match the route paths.

In the $_SERVER var, I have these. Which one does Slim use to match against paths?

[SCRIPT_URL] => /test

So I’m accessing:

I added these lines right before $app->run():

print "URI: " . $app->getContainer()->get(‘request’)->getUri();
print "PATH: " . $app->getContainer()->get(‘request’)->getUri()->getPath();

This is the output:

So why would the URI have the trailing forward slash? Also, when getting the path, why would it NOT include the first path dir ‘test’?