mrjayviper
mrjayviper

Reputation: 2388

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

summary:

  1. my-host-here.com/app_dev.php/main = works

  2. my-host-here.com/main = 404 error

  3. my-host-here.com/app.php/main = also gets a 404 error

I've looked at various links (symfony.com 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/mod_reqtimeout.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule slotmem_plain_module modules/mod_slotmem_plain.so

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

LoadModule php5_module modules/libphp5.so

snippet of my virtualhost config file

<VirtualHost *:80>
ServerName my-host-here.com
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]
 </IfModule>
</Directory>

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

Upvotes: 0

Views: 165

Answers (1)

blues911
blues911

Reputation: 910

Here is my settings:

/etc/apache2/sites-available/project.conf

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

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

    ErrorLog /path/to/project/error.log
    CustomLog /path/to/project/access.log combined
  </VirtualHost>

web/.htaccess

<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]
</IfModule>

Upvotes: 1

Related Questions