Symfony2 throwing 404 inside kernel request event

✔ Recommended Answer

You could return a 404 response instead of throwing an exception:

public function onKernelRequest(GetResponseEvent $event){    // find domain in cache/database...    if (!$domain) {        $event->setResponse(new Response('Not found!', 404));    }    // store domain in service...}


Answered By: gblock

Method #2

When Symfony2 throws a 404 error inside the kernel request event, it usually means that the requested resource or route does not exist.

The kernel request event is triggered at the beginning of each request, so if a route or resource is not found at this point, Symfony2 will throw a 404 error.

To troubleshoot this issue, you can try the following steps:

  1. Check the requested URL: Make sure the URL being requested is correct and matches a defined route in your application.

  2. Check your routing configuration: Ensure that your routing configuration is correct and that the requested route is defined.

  3. Check your controller and action methods: Ensure that the controller and action methods exist and are correctly defined.

  4. Check your file permissions: Make sure that the file or directory being requested has the correct file permissions set to allow access.

  5. Check for any redirects or middleware: Ensure that there are no redirects or middleware that could be causing the 404 error.

  6. Check your server logs: Review your server logs to see if there are any relevant error messages or clues as to what may be causing the 404 error.

By following these steps, you should be able to identify and resolve the issue causing the 404 error in Symfony2.


Most Popular

Remove Unicode Zero Width Space PHP

PhpStorm, return value is expected to be 'A', 'object' returned

Laravel file upload returns forbidden 403, file permission is 700 not 755