title: Symfony2 production; Apache VirtualHost not working
body: <p>I'm a novice to Symfony2 and MVC frameworks but have some experience with PHP and Apache.</p>
  
  <p>I developed a project on an Apache server on my workstation. I'm trying to deploy my first Symfony2 project on our production Ubuntu server, also running Apache. For some reason I cannot get the behavior I want. The server is running multiple virtual hosts just fine. However, when attempting to go to where the Symfony2 project <em>should</em> show up, I instead get a listing of the directory contents at the root level of the Symfony2 project (though the vhost is pointing to the /web subdirectory). If I manually navigate to the web directory I can get to the project clicking on either the app_dev.php or app.php front controllers, however app.php and app_dev.php persist when using the project instead of giving "pretty" URLs (with the fc hidden).</p>
  
  <p>I've searched for solutions and tried using ./app/console --env=prod cache:clear to no avail. Apache mod_rewrite is enabled, and the Symfony2 default .htaccess file should be handling rewrites even if my vhost isn't (which would be preferred).</p>
  
  <p>Thank you for any help!</p>
  
  <p>Main vhost:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerName server.com
      ServerAlias www.server.com
      ServerAdmin webmaster@server.com
  
      DocumentRoot /var/www/main/public
  
      &lt;Directory /var/www/main/public&gt;
          AllowOverride all
          Order allow,deny
          Allow from all
          Options MultiViews Indexes FollowSymlinks IncludesNoExec
      &lt;/Directory&gt;
  
      &lt;Location /&gt;
          # The main site was done in Zend Framework which uses this.
          SetEnv APPLICATION_ENV "production"
          RewriteEngine On
          RewriteCond %{REQUEST_FILENAME} -s [OR]
          RewriteCond %{REQUEST_FILENAME} -l [OR]
          RewriteCond %{REQUEST_FILENAME} -d
          RewriteRule ^.*$ - [NC,L]
          RewriteRule ^.*$ index.php [NC,L]
      &lt;/Location&gt;
  
      ErrorLog /var/log/apache2/error-main.log
      LogLevel error
  
      CustomLog /var/log/apache2/access-main.log combined
      ServerSignature On
  
      Alias /project /var/www/project/web
  
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>Project vhost:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
  
      DocumentRoot /var/www/project/web
      Alias /project /var/www/project/web
  
      &lt;Directory /var/www/project/web/&gt;
          Options Indexes FollowSymLinks MultiViews
          AllowOverride All
          Order allow,deny
          allow from all
  
          DirectoryIndex app.php
  
      &lt;/Directory&gt;
  
      ErrorLog ${APACHE_LOG_DIR}/error-project.log
  
      # Possible values include: debug, info, notice, warn, error, crit,
      # alert, emerg.
      LogLevel info
  
      CustomLog ${APACHE_LOG_DIR}/access-project.log combined
  
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>Using the default .htaccess file in project/web/</p>
  
  <pre><code># Use the front controller as index file. It serves as fallback solution when
  # every other rewrite/redirect fails (e.g. in an aliased environment without
  # mod_rewrite). Additionally, this reduces the matching process for the
  # startpage (path "/") because otherwise Apache will apply the rewritting rules
  # to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
  DirectoryIndex app.php
  
  &lt;IfModule mod_rewrite.c&gt;
      RewriteEngine On
  
      # Redirect to URI without front controller to prevent duplicate content
      # (with and without `/app.php`). Only do this redirect on the initial
      # rewrite by Apache and not on subsequent cycles. Otherwise we would get an
      # endless redirect loop (request -&gt; rewrite to front controller -&gt;
      # redirect -&gt; request -&gt; ...).
      # So in case you get a "too many redirects" error or you always get redirected
      # to the startpage because your Apache does not expose the REDIRECT_STATUS
      # environment variable, you have 2 choices:
      # - disable this feature by commenting the following 2 lines or
      # - use Apache &gt;= 2.3.9 and replace all L flags by END flags and remove the
      #   following RewriteCond (best solution)
      RewriteCond %{ENV:REDIRECT_STATUS} ^$
      RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
  
      # If the requested filename exists, simply serve it.
      # We only want to let Apache serve files and not directories.
      RewriteCond %{REQUEST_FILENAME} -f
      RewriteRule .? - [L]
  
      # The following rewrites all other queries to the front controller. The
      # condition ensures that if you are using Apache aliases to do mass virtual
      # hosting, the base path will be prepended to allow proper resolution of the
      # app.php file; it will work in non-aliased environments as well, providing
      # a safe, one-size fits all solution.
      RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
      RewriteRule ^(.*) - [E=BASE:%1]
      RewriteRule .? %{ENV:BASE}app.php [L]
  &lt;/IfModule&gt;
  
  &lt;IfModule !mod_rewrite.c&gt;
      &lt;IfModule mod_alias.c&gt;
          # When mod_rewrite is not available, we instruct a temporary redirect of
          # the startpage to the front controller explicitly so that the website
          # and the generated links can still be used.
          RedirectMatch 302 ^/$ /app.php/
          # RedirectTemp cannot be used instead
      &lt;/IfModule&gt;
  &lt;/IfModule&gt;
  </code></pre>