You will need to write an event listener. You are going to subscribe to the kernel exception. Check if the exception is a MethodNotAllowedException and then translate it to a NotFoundException.
//Your Event Listener
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
class ExceptionListener
{
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
if (!($exception instanceof MethodNotAllowedException)) {
return;
}
$response = new Response($exception->getMessage(),404);
$event->setResponse($response);
}
}
Have a look at the Symfony Documentation on how to create and register your event listener.