<p dir="auto"><strong>Symfony version(s) affected</strong>: 4.1.1</p>
<p dir="auto"><strong>Description</strong><br>
I'm working on a microservice that does not have a homepage, because we have this policy of prefixing our APIs with <code class="notranslate">/api</code>. 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 <code class="notranslate">NoConfigurationException</code></p>
<p dir="auto">Here is what I believe is the configuration responsible for this:</p>
<p dir="auto"></p><div class="Box Box--condensed my-2">
  <div class="Box-header f6">
    <p class="mb-0 text-bold">
      <a href="https://github.com/symfony/symfony/blob/adb137d5c1f5c2b0831b5135c0e171b46bac81ca/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php#L198">symfony/src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php</a>
    </p>
    <p class="mb-0 color-fg-muted">
         Line 198
      in
      <a data-pjax="true" class="commit-tease-sha" href="/symfony/symfony/commit/adb137d5c1f5c2b0831b5135c0e171b46bac81ca">adb137d</a>
    </p>
  </div>
  <div itemprop="text" class="Box-body p-0 blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">

        <tbody><tr class="border-0">
          <td id="L198" class="blob-num border-0 px-3 py-0 color-bg-default" data-line-number="198"></td>
          <td id="LC198" class="blob-code border-0 px-3 py-0 color-bg-default blob-code-inner js-file-line"> <span class="pl-s1"><span class="pl-c1">$</span>code</span> .= "<span class="pl-s">            throw new Symfony\Component\Routing\Exception\NoConfigurationException();</span>\n"; </td>
        </tr>
    </tbody></table>
  </div>
</div>
<p></p>
<p dir="auto"><strong>How to reproduce</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="cd /tmp
composer create-project symfony/skeleton
cd skeleton
sed -i 's/dev/prod/' .env
php -S 127.0.0.1:8000 -t public"><pre class="notranslate"><code class="notranslate">cd /tmp
composer create-project symfony/skeleton
cd skeleton
sed -i 's/dev/prod/' .env
php -S 127.0.0.1:8000 -t public
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[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-&gt;doMatch('/', Array, Array)
#1 /tmp/skeleton/vendor/symfony/routing/Matcher/UrlMatcher.php(107): srcProdProjectContainerUrlMatcher-&gt;match('/')
#2 /tmp/skeleton/vendor/symfony/routing/Router.php(262): Symfony\Component\Routing\Matcher\UrlMatcher-&gt;matchRequest(Object(Symfony\Component\HttpFoundation\Request))
#3 /tmp/skeleton/vendor/symfony/http-kernel/EventListener/RouterListener.php(115): Symfony\Component\Routing\Router-&gt;matchRequest(Object(Symfony\Component\HttpFoundation\Request))
#4 /tmp/skeleton/vendor/symfony/event-dispatcher/EventDispatcher.php(212): Symfony\Component\HttpKernel\EventListener\RouterListener-&gt;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-&gt;doMatch('/', Array, Array)
#1 /tmp/skeleton/vendor/symfony/routing/Matcher/UrlMatcher.php(107): srcProdProjectContainerUrlMatcher-&gt;match('/')
#2 /tmp/skeleton/vendor/symfony/routing/Router.php(262): Symfony\Component\Routing\Matcher\UrlMatcher-&gt;matchRequest(Object(Symfony\Component\HttpFoundation\Request))
#3 /tmp/skeleton/vendor/symfony/http-kernel/EventListener/RouterListener.php(115): Symfony\Component\Routing\Router-&gt;matchRequest(Object(Symfony\Component\HttpFoundation\Request))
#4 /tmp/skeleton/vendor/symfony/event-dispatcher/EventDispatcher.php(212): Symfony\Component\HttpKernel\EventListener\RouterListener-&gt;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

"><pre lang="2018-07-13T15:05:48+00:00" class="notranslate"><code class="notranslate">[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-&gt;doMatch('/', Array, Array)
#1 /tmp/skeleton/vendor/symfony/routing/Matcher/UrlMatcher.php(107): srcProdProjectContainerUrlMatcher-&gt;match('/')
#2 /tmp/skeleton/vendor/symfony/routing/Router.php(262): Symfony\Component\Routing\Matcher\UrlMatcher-&gt;matchRequest(Object(Symfony\Component\HttpFoundation\Request))
#3 /tmp/skeleton/vendor/symfony/http-kernel/EventListener/RouterListener.php(115): Symfony\Component\Routing\Router-&gt;matchRequest(Object(Symfony\Component\HttpFoundation\Request))
#4 /tmp/skeleton/vendor/symfony/event-dispatcher/EventDispatcher.php(212): Symfony\Component\HttpKernel\EventListener\RouterListener-&gt;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-&gt;doMatch('/', Array, Array)
#1 /tmp/skeleton/vendor/symfony/routing/Matcher/UrlMatcher.php(107): srcProdProjectContainerUrlMatcher-&gt;match('/')
#2 /tmp/skeleton/vendor/symfony/routing/Router.php(262): Symfony\Component\Routing\Matcher\UrlMatcher-&gt;matchRequest(Object(Symfony\Component\HttpFoundation\Request))
#3 /tmp/skeleton/vendor/symfony/http-kernel/EventListener/RouterListener.php(115): Symfony\Component\Routing\Router-&gt;matchRequest(Object(Symfony\Component\HttpFoundation\Request))
#4 /tmp/skeleton/vendor/symfony/event-dispatcher/EventDispatcher.php(212): Symfony\Component\HttpKernel\EventListener\RouterListener-&gt;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


</code></pre></div>
<p dir="auto"><strong>Possible Solution</strong><br>
Catch the exception somehwere?</p>
<table role="table">
<thead>
<tr>
<th>Q</th>
<th>A</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bug report?</td>
<td>no</td>
</tr>
<tr>
<td>Feature request?</td>
<td>yes</td>
</tr>
<tr>
<td>BC Break report?</td>
<td>no</td>
</tr>
<tr>
<td>RFC?</td>
<td>no</td>
</tr>
</tbody>
</table>

<h2 dir="auto">Steps to reproduce:</h2>
<p dir="auto">Create a project:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="composer create-project symfony/skeleton symfony-skeleton"><pre class="notranslate"><code class="notranslate">composer create-project symfony/skeleton symfony-skeleton
</code></pre></div>
<p dir="auto">Set the app environment to prod:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="sed -i -e 's/APP_ENV=dev/APP_ENV=prod/g' .env"><pre class="notranslate"><code class="notranslate">sed -i -e 's/APP_ENV=dev/APP_ENV=prod/g' .env
</code></pre></div>
<p dir="auto">This can be shown also with setting the APP_ENV environment variable.</p>
<p dir="auto">Add a <a href="https://symfony.com/doc/current/page_creation.html" rel="nofollow">simple controller and a route</a>.</p>
<p dir="auto">Add an <code class="notranslate">.htaccess</code> file in /public as follows (we use Apache):</p>
<div class="highlight highlight-source-apache-config notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="&lt;IfModule mod_rewrite.c&gt;
    Options -MultiViews
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
&lt;/IfModule&gt;"><pre class="notranslate">&lt;<span class="pl-ent">IfModule</span> mod_rewrite.c&gt;
    <span class="pl-c1">Options</span> -MultiViews
    <span class="pl-c1">RewriteEngine</span> On
    <span class="pl-c1">RewriteCond</span> <span class="pl-c1">%{REQUEST_FILENAME}</span> <span class="pl-s">!-f</span>
    <span class="pl-c1">RewriteRule</span> <span class="pl-sr">^(.*)$</span> <span class="pl-s">index.php</span> <span class="pl-sr">[QSA,L]</span>
&lt;/<span class="pl-ent">IfModule</span>&gt;</pre></div>
<p dir="auto">Try to get "/foo". In the prod environment, ResourceNotFoundException is not caught or converted to a 404:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2018-01-18T15:53:46-05:00 [critical] Uncaught Exception: No route found for &quot;GET
/foo&quot; [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-&gt;match('/foo')\n#1
vendor/symfony/routing/Router.php(262): Symfony\\Component\\Routing\\Matcher\\Ur
lMatcher-&gt;matchRequest(Object(Symfony\\Component\\HttpFoundation\\Request))\n#2
vendor/symfony/http-kernel/EventListener/RouterListener.php(109): Symfony\\Compo
nent\\Routing\\Router-&gt;matchRequest(Object(Symfony\\Component\\HttpFoundation\\R
equest))\n#3 vendor/symfony/event-dispatcher/EventDispatcher.php(212): Symfony\\
Component\\HttpKernel\\EventListener\\RouterListener-&gt;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"><pre class="notranslate"><code class="notranslate">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-&gt;match('/foo')\n#1
vendor/symfony/routing/Router.php(262): Symfony\\Component\\Routing\\Matcher\\Ur
lMatcher-&gt;matchRequest(Object(Symfony\\Component\\HttpFoundation\\Request))\n#2
vendor/symfony/http-kernel/EventListener/RouterListener.php(109): Symfony\\Compo
nent\\Routing\\Router-&gt;matchRequest(Object(Symfony\\Component\\HttpFoundation\\R
equest))\n#3 vendor/symfony/event-dispatcher/EventDispatcher.php(212): Symfony\\
Component\\HttpKernel\\EventListener\\RouterListener-&gt;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
</code></pre></div>