mrjayviper mrjayviper - 4 years ago 439
Apache Configuration Question

Symfony2.8.x: how to configure Apache to remove "web/app.php" from my URL?


  1. = works

  2. = 404 error

  3. = also gets a 404 error

I've looked at various links ( and discussions here in SO) and tried their suggestions/answers but no luck here.

Any ideas on how to fix it? Thanks a lot!

I'm using Apache 2.4.x/PHP 5.4.x which were installed using the yum repository on RHEL7.

snippet of httpd.conf

Include conf.modules.d/*.conf

snippet of 00-base.conf which resides inside conf.modules.d

LoadModule reqtimeout_module modules/
LoadModule rewrite_module modules/
LoadModule setenvif_module modules/
LoadModule slotmem_plain_module modules/

snippet of 10-php.conf which resides inside conf.modules.d

LoadModule php5_module modules/

snippet of my virtualhost config file

<VirtualHost *:80>
DocumentRoot /opt/www/my-host-here/web

<Directory /opt/www/my-host-here/web/>
DirectoryIndex app.php
AllowOverride All
Require all granted

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

The contents of the .htaccess inside /opt/www/my-host-here/web is whatever Symfony came with. I never changed it. Symfony project was created using the command:

symfony new my_project_name lts

Answer Source

Here is my settings:


  <VirtualHost *:80>
    ServerName project       
    DocumentRoot /path/to/project/web 

    <Directory /path/to/project/web >
        Options Indexes FollowSymlinks
        AllowOverride All
        Require all granted

    ErrorLog /path/to/project/error.log
    CustomLog /path/to/project/access.log combined


<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Explicitly disable rewriting for front controllers
    # RewriteRule ^app.php - [L]
    RewriteRule ^app_dev.php - [L]

    RewriteCond %{REQUEST_FILENAME} !-f

    # Change below before deploying to production
    # RewriteRule ^(.*)$ app.php [QSA,L]
    RewriteRule ^(.*)$ app_dev.php [QSA,L]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download