title: Exception Symfony\Component\Routing\Exception\ResourceNotFoundException [Symfony 2.4]
body: <p>I am using a custom controller which all my other controllers will extend instead of Symfony's basic controller class.</p>
  
  <p>Everything works fine in prod env except for one route (which works fine on localhost btw).</p>
  
  <p>Here is the route that causes this exception:</p>
  
  <pre><code>acme_change_lang:
      pattern:  /changeLang/{locale}/
      defaults: { _controller: AcmeBundle:Acme:changeLang}
  </code></pre>
  
  <p>CoreController:</p>
  
  <pre><code>class CoreController extends Controller
  {
      private $_locales;
  
      public function __construct() {
          //if set to true then the language is active. False means the language cannot be used at the moment.
          $this-&gt;_locales = array('en' =&gt; true, 'fr' =&gt; true);
      }
  
      .....
  
      protected function getRefererRoute(Request $request = null)
      {
          if ($request == null)
              $request = $this-&gt;getRequest();
  
          //look for the referer route
          $referer = $request-&gt;headers-&gt;get('referer');
          $lastPath = substr($referer, strpos($referer, $request-&gt;getBaseUrl()));
          $lastPath = str_replace($request-&gt;getBaseUrl(), '', $lastPath);
  
          $matcher = $this-&gt;get('router')-&gt;getMatcher();
          $parameters = $matcher-&gt;match($lastPath);
          $route = $parameters['_route'];
  
          return $route;
      }
  
      protected function setSession(Request $request, $loc = '') {
          $session = $request-&gt;getSession();
  
          if (empty($loc) OR !isset($this-&gt;_locales[$loc]) OR $this-&gt;_locales[$loc] == false)
              $loc = 'en';
          $session-&gt;set('locale', $loc);
      }
  
      public function changeLangAction(Request $request, $locale) {
          $this-&gt;setSession($request, $locale);
          return ($this-&gt;redirect($this-&gt;generateUrl($this-&gt;getRefererRoute($request))));
      }
  
     .....
  }
  
  
  [2014-11-15 18:54:14] request.INFO: Matched route "acme_change_lang" (parameters: "_controller": "Acme\Bundle\AcmeBundle\Controller\AcmeController::changeLangAction", "locale": "en", "_route": "acme_change_lang") [] []
  [2014-11-15 18:54:14] request.CRITICAL: Uncaught PHP Exception Symfony\Component\Routing\Exception\ResourceNotFoundException: "" at /home/fakePath/www/app/cache/prod/appProdUrlMatcher.php line 66 {"exception":"[object] (Symfony\\Component\\Routing\\Exception\\ResourceNotFoundException:  at /home/fakePath/www/app/cache/prod/appProdUrlMatcher.php:66)"} []
  </code></pre>
  
  <p>The thing I don't understand is that it says it has found a matching route and then throws that exception.</p>
  
  <p>Any ideas about what is causing this ?</p>