# Slim 4 Error HttpNotFoundException

**URL:** <https://discourse.slimframework.com/t/slim-4-error-httpnotfoundexception/4178>\
**Category:** Questions\
**Created:** [May 19, 2020, 10:58am UTC](https://discourse.slimframework.com/t/slim-4-error-httpnotfoundexception/4178 "2020-05-19T10:58:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vino](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@Vino](https://discourse.slimframework.com/u/Vino)\
**Post date:** [May 19, 2020, 10:58am UTC](https://discourse.slimframework.com/t/slim-4-error-httpnotfoundexception/4178/1 "2020-05-19T10:58:08Z")

</div>

Hi All,

Request your help, below is my code, the code is working as expected with any error in the front end, however it throws the below error in the backend log.

**Error**

```auto
[Tue May 19 10:52:48.080893 2020] [proxy_fcgi:error] [pid 16381] [client 16.10.39.72:51740] AH01071: Got error 'PHP message: 404 Not Found\nType: Slim\\Exception\\HttpNotFoundException\nCode: 404\nMessage: Not found.\nFile: /var/project/tech/web/includes/source4/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php\nLine: 93\nTrace: #0 /var/project/tech/web/includes/source4/vendor/slim/slim/Slim/Routing/RouteRunner.php(72): Slim\\Middleware\\RoutingMiddleware->performRouting(Object(Nyholm\\Psr7\\ServerRequest))\n#1 /var/project/tech/web/includes/source4/vendor/slim/twig-view/src/TwigMiddleware.php(125): Slim\\Routing\\RouteRunner->handle(Object(Nyholm\\Psr7\\ServerRequest))\n#2 /var/project/tech/web/includes/source4/vendor/slim/slim/Slim/MiddlewareDispatcher.php(140): Slim\\Views\\TwigMiddleware->process(Object(Nyholm\\Psr7\\ServerRequest), Object(Slim\\Routing\\RouteRunner))\n#3 /var/project/tech/web/includes/source4/vendor/slim/slim/Slim/Middleware/ErrorMiddleware.php(107): class@anonymous->handle(Object(Nyholm\\Psr7\\ServerRequest))\n#4 /var/project/saptec...\n', referer: https://devtech.com:8130/

```

**Code**

```auto
<?php
use DI\Container;
use Slim\Factory\AppFactory;
use Slim\Views\Twig;
use Slim\Views\TwigMiddleware;
use Slim\Exception\NotFoundException;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
use Slim\Routing\RouteCollectorProxy;

$container = new Container();
AppFactory::setContainer($container);
$container->set('view', function() { return Twig::create('../tpl'); });
$app = AppFactory::create();
$app->add(TwigMiddleware::createFromContainer($app));
$app->addErrorMiddleware(true, true, true);

$app->group('', function(RouteCollectorProxy $group) {
      $group->get('/f101', function($request, $response) {
            $am = new amsrvinfo();
            $SList = $am->getSList();
            return $this->get('view')->render($response, 'page_srv.html', array ("SList" => $SList));
      })->setName('ServerInfo');
	        $group->get('/f102', function($request, $response) {
            $am = new amlocinfo();
            $LList = $am->getSList();
            return $this->get('view')->render($response, 'page_loc.html', array ("LList" => $LList));
      })->setName('ServerInfo');
	        $group->get('/f103', function($request, $response) {
            $am = new amracinfo();
            $RList = $am->getSList();
            return $this->get('view')->render($response, 'page_rac.html', array ("RList" => $RList));
      })->setName('ServerInfo');
});
$app->run();

?>

```

---

<div class="post-metadata">

**Author:** ![Vino](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@Vino](https://discourse.slimframework.com/u/Vino)\
**Post date:** [May 19, 2020, 12:14pm UTC](https://discourse.slimframework.com/t/slim-4-error-httpnotfoundexception/4178/2 "2020-05-19T12:14:38Z")

</div>

Hi All,

Tried adding base path and other configuration as stated in the below link , sill no luck  
**[https://github.com/selective-php/basepath](https://github.com/selective-php/basepath)**

```auto
use DI\Container;
use Slim\Factory\AppFactory;
use Slim\Views\Twig;
use Slim\Views\TwigMiddleware;
use Slim\Exception\NotFoundException;
use Slim\Routing\RouteCollectorProxy;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
use Selective\BasePath\BasePathDetector;
use Selective\BasePath\BasePathMiddleware;
require '../includes/source4/vendor/autoload.php';

$container = new Container();
AppFactory::setContainer($container);
$container->set('view', function() { return Twig::create('../tpl', ['cache' => false]); });
$basePathDetector = new BasePathDetector($_SERVER);
$basePath = $basePathDetector->getBasePath();
$app = AppFactory::create();
$app->add(TwigMiddleware::createFromContainer($app));
$app->addRoutingMiddleware();
$app->add(new BasePathMiddleware($app));
$app->addErrorMiddleware(true, true, true);

```

---

<div class="post-metadata">

**Author:** ![Vino](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@Vino](https://discourse.slimframework.com/u/Vino)\
**Post date:** [May 19, 2020, 3:04pm UTC](https://discourse.slimframework.com/t/slim-4-error-httpnotfoundexception/4178/3 "2020-05-19T15:04:34Z")

</div>

Hi All,

Was able to resolve this issue by reordering, I tried to find the base path setting in the Slim4 documentation and was not able to find one, as per this issue it seem that setting basepath is important, so can we add it to the documentation please.

**Code**

```auto
$container = new Container();
AppFactory::setContainer($container);
$container->set('view', function() { return Twig::create('../tpl', ['cache' => false]); });
$app = AppFactory::create();
$app->addRoutingMiddleware();
$basePath = (new BasePathDetector($_SERVER))->getBasePath();
$app->setBasePath($basePath);
$app->add(TwigMiddleware::createFromContainer($app));
$app->addErrorMiddleware(true, true, true);

```

---

<div class="post-metadata">

**Author:** ![Vino](https://avatars.discourse-cdn.com/v4/letter/v/c2a13f/32.png) [@Vino](https://discourse.slimframework.com/u/Vino)\
**Post date:** [May 24, 2020, 10:49pm UTC](https://discourse.slimframework.com/t/slim-4-error-httpnotfoundexception/4178/4 "2020-05-24T22:49:31Z")

</div>

Hi All,

At last the issue got resolved, the issue was at the apache side.
