# Page Not Found - 404

**URL:** <https://discourse.slimframework.com/t/page-not-found-404/1908>\
**Category:** Questions\
**Created:** [October 19, 2017, 6:44pm UTC](https://discourse.slimframework.com/t/page-not-found-404/1908 "2017-10-19T18:44:54Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![r7890](https://avatars.discourse-cdn.com/v4/letter/r/8dc957/32.png) [@r7890](https://discourse.slimframework.com/u/r7890)\
**Post date:** [October 19, 2017, 6:44pm UTC](https://discourse.slimframework.com/t/page-not-found-404/1908/1 "2017-10-19T18:44:54Z")

</div>

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.

> RewriteCond %{DOCUMENT\_ROOT}%{REQUEST\_FILENAME} !-f  
> RewriteRule ^.\* /controller.php [QSA,L]

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

controller.php looks like this:  
\<?php  
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));

 });
 $app->run();

```

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?

---

<div class="post-metadata">

**Author:** ![andriesvw](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/andriesvw/32/513_2.png) [@andriesvw](https://discourse.slimframework.com/u/andriesvw)\
**Post date:** [October 19, 2017, 7:24pm UTC](https://discourse.slimframework.com/t/page-not-found-404/1908/2 "2017-10-19T19:24:35Z")

</div>

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’ );

---

<div class="post-metadata">

**Author:** ![andriesvw](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/andriesvw/32/513_2.png) [@andriesvw](https://discourse.slimframework.com/u/andriesvw)\
**Post date:** [October 19, 2017, 7:25pm UTC](https://discourse.slimframework.com/t/page-not-found-404/1908/3 "2017-10-19T19:25:26Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andriesvw](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/andriesvw/32/513_2.png) [@andriesvw](https://discourse.slimframework.com/u/andriesvw)\
**Post date:** [October 19, 2017, 7:29pm UTC](https://discourse.slimframework.com/t/page-not-found-404/1908/4 "2017-10-19T19:29:16Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![r7890](https://avatars.discourse-cdn.com/v4/letter/r/8dc957/32.png) [@r7890](https://discourse.slimframework.com/u/r7890)\
**Post date:** [October 19, 2017, 7:31pm UTC](https://discourse.slimframework.com/t/page-not-found-404/1908/5 "2017-10-19T19:31:39Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![andriesvw](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/andriesvw/32/513_2.png) [@andriesvw](https://discourse.slimframework.com/u/andriesvw)\
**Post date:** [October 19, 2017, 7:33pm UTC](https://discourse.slimframework.com/t/page-not-found-404/1908/6 "2017-10-19T19:33:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![r7890](https://avatars.discourse-cdn.com/v4/letter/r/8dc957/32.png) [@r7890](https://discourse.slimframework.com/u/r7890)\
**Post date:** [October 19, 2017, 7:36pm UTC](https://discourse.slimframework.com/t/page-not-found-404/1908/7 "2017-10-19T19:36:17Z")

</div>

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  
RewriteCond %{DOCUMENT\_ROOT}%{REQUEST\_FILENAME} !-f  
RewriteCond %{DOCUMENT\_ROOT}%{REQUEST\_FILENAME} !-d  
RewriteRule ^ controller.php [QSA,L]

---

<div class="post-metadata">

**Author:** ![andriesvw](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/andriesvw/32/513_2.png) [@andriesvw](https://discourse.slimframework.com/u/andriesvw)\
**Post date:** [October 19, 2017, 7:36pm UTC](https://discourse.slimframework.com/t/page-not-found-404/1908/8 "2017-10-19T19:36:46Z")

</div>

Champion! Well done!

---

<div class="post-metadata">

**Author:** ![r7890](https://avatars.discourse-cdn.com/v4/letter/r/8dc957/32.png) [@r7890](https://discourse.slimframework.com/u/r7890)\
**Post date:** [October 19, 2017, 7:41pm UTC](https://discourse.slimframework.com/t/page-not-found-404/1908/9 "2017-10-19T19:41:09Z")

</div>

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
[SCRIPT_URI] => https://myserver.com/test
```

---

<div class="post-metadata">

**Author:** ![r7890](https://avatars.discourse-cdn.com/v4/letter/r/8dc957/32.png) [@r7890](https://discourse.slimframework.com/u/r7890)\
**Post date:** [October 19, 2017, 7:57pm UTC](https://discourse.slimframework.com/t/page-not-found-404/1908/10 "2017-10-19T19:57:53Z")

</div>

So I’m accessing: [myserver.com/test](http://myserver.com/test)

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:  
URI: [https://myserver.com/test/](https://myserver.com/test/)  
PATH: /

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’?
