Search code examples
symfonynginxproduction-environment

Symfony2 and production environment - allways displays app_dev in links


I have a symfony2 project running with nginx and the problem is that when accessing the prod environment, all the links are still with app_dev.php there.

Here are my config files:

app.php

<?php

require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';

use Symfony\Component\HttpFoundation\Request;

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$kernel->handle(Request::createFromGlobals())->send(); 

The links in the twig file are called this way:

Route name: user_login, in twig: user_login_path()

Where could the problem come from? Nginx?


Solution

  • You should always use path('route_name') in order to generate links or actions. It seems that the function(s) you are using (kind of twig extension) is bad coded and server dependent. But it does not comes with Symfony itself.

    You have multiple options :

    • The cleanest : replace every href, action, ... with the path function
    • A (maybe) faster one : find the custom twig extension and make it work (more likely in src/Acme/MyBundle/Twig/MyExtension.php)
    • A quick and dirty one : rewrite every app_dev.php urls to app.dev with a .htaccess (not really recommended at all but... well...)