Issue 1:
Symfony version(s) affected: 4.1.1

Description

I'm working on a microservice that does not have a homepage, because we have this policy of prefixing our APIs with /api. I didn't configuration a homepage, and while in dev, I get a welcome page aimed at developers, in production, I get a 500 because this welcome page is displayed by throwing a NoConfigurationException

Here is what I believe is the configuration responsible for this:

symfony/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php

Line 198
in
adb137d

$code .= " throw new Symfony\Component\Routing\Exception\NoConfigurationException();\n";

How to reproduce

cd /tmp
composer create-project symfony/skeleton
cd skeleton
sed -i 's/dev/prod/' .env
php -S 127.0.0.1:8000 -t public

[Fri Jul 13 17:05:48 2018] PHP Fatal error: Uncaught Symfony\Component\Routing\Exception\NoConfigurationException in /tmp/skeleton/var/cache/prod/srcProdProjectContainerUrlMatcher.php:65
Stack trace:
#0 /tmp/skeleton/var/cache/prod/srcProdProjectContainerUrlMatcher.php(21): srcProdProjectContainerUrlMatcher->doMatch('/', Array, Array)
#1 /tmp/skeleton/vendor/symfony/routing/Matcher/UrlMatcher.php(107): srcProdProjectContainerUrlMatcher->match('/')
#2 /tmp/skeleton/vendor/symfony/routing/Router.php(262): Symfony\Component\Routing\Matcher\UrlMatcher->matchRequest(Object(Symfony\Component\HttpFoundation\Request))
#3 /tmp/skeleton/vendor/symfony/http-kernel/EventListener/RouterListener.php(115): Symfony\Component\Routing\Router->matchRequest(Object(Symfony\Component\HttpFoundation\Request))
#4 /tmp/skeleton/vendor/symfony/event-dispatcher/EventDispatcher.php(212): Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(Object(Symfony\Component\HttpKernel\Event\GetResponseEvent), 'kernel.request', Object(Symfony\Component\EventDispatcher\ in /tmp/skeleton/vendor/symfony/http-kernel/EventListener/RouterListener.php on line 139
[Fri Jul 13 17:05:48 2018] 127.0.0.1:51332 [500]: / - Uncaught Symfony\Component\Routing\Exception\NoConfigurationException in /tmp/skeleton/var/cache/prod/srcProdProjectContainerUrlMatcher.php:65
Stack trace:
#0 /tmp/skeleton/var/cache/prod/srcProdProjectContainerUrlMatcher.php(21): srcProdProjectContainerUrlMatcher->doMatch('/', Array, Array)
#1 /tmp/skeleton/vendor/symfony/routing/Matcher/UrlMatcher.php(107): srcProdProjectContainerUrlMatcher->match('/')
#2 /tmp/skeleton/vendor/symfony/routing/Router.php(262): Symfony\Component\Routing\Matcher\UrlMatcher->matchRequest(Object(Symfony\Component\HttpFoundation\Request))
#3 /tmp/skeleton/vendor/symfony/http-kernel/EventListener/RouterListener.php(115): Symfony\Component\Routing\Router->matchRequest(Object(Symfony\Component\HttpFoundation\Request))
#4 /tmp/skeleton/vendor/symfony/event-dispatcher/EventDispatcher.php(212): Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(Object(Symfony\Component\HttpKernel\Event\GetResponseEvent), 'kernel.request', Object(Symfony\Component\EventDispatcher\ in /tmp/skeleton/vendor/symfony/http-kernel/EventListener/RouterListener.php on line 139
[1] 7903 segmentation fault (core dumped) php -S 127.0.0.1:8000 -t public

Possible Solution

Catch the exception somehwere?

Issue 2:
Q
A

Bug report?
no

Feature request?
yes

BC Break report?
no

RFC?
no

Steps to reproduce:

Create a project:

composer create-project symfony/skeleton symfony-skeleton

Set the app environment to prod:

sed -i -e 's/APP_ENV=dev/APP_ENV=prod/g' .env

This can be shown also with setting the APP_ENV environment variable.

Add a simple controller and a route.

Add an .htaccess file in /public as follows (we use Apache):

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

Try to get "/foo". In the prod environment, ResourceNotFoundException is not caught or converted to a 404:

2018-01-18T15:53:46-05:00 [critical] Uncaught Exception: No route found for "GET
/foo" [Thu Jan 18 15:53:46.592760 2018] [php7:notice] [pid 66514] [client
::1:58156] PHP Fatal error: Uncaught
Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException in
var/cache/prod/srcProdProjectContainerUrlMatcher.php:38\nStack trace:\n#0
vendor/symfony/routing/Matcher/UrlMatcher.php(95):
srcProdProjectContainerUrlMatcher->match('/foo')\n#1
vendor/symfony/routing/Router.php(262): Symfony\\Component\\Routing\\Matcher\\Ur
lMatcher->matchRequest(Object(Symfony\\Component\\HttpFoundation\\Request))\n#2
vendor/symfony/http-kernel/EventListener/RouterListener.php(109): Symfony\\Compo
nent\\Routing\\Router->matchRequest(Object(Symfony\\Component\\HttpFoundation\\R
equest))\n#3 vendor/symfony/event-dispatcher/EventDispatcher.php(212): Symfony\\
Component\\HttpKernel\\EventListener\\RouterListener->onKernelRequest(Object(Sym
fony\\Component\\HttpKernel\\Event\\GetResponseEvent), 'kernel.request',
Object(Symfony\\Component\\EventDispatcher\\EventDispatcher))\n#4 /Users/cjm/Si
in vendor/symfony/http-kernel/EventListener/RouterListener.php on line 139