Hugo Fouquet Hugo Fouquet - 6 months ago 36
PHP Question

Config Symfony3 URL

I use a debian server and I want change my URL

ipAdresse:9999/app.php/register
with
isAdress/register
.

I have succeed to remove the
.../web/...
. But not the
.../app.php/...


I have a virtual host :

Listen ipAdress:9999

<VirtualHost ipAdress:9999>
DocumentRoot "/var/www/SuperSwungBall/web"
DirectoryIndex app.php


<Directory "/var/www/SuperSwungBall/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>


And a .htaccess in ~/web :

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


I have also tried with the default symfony ~/web/.htaccess . But, it doesn't work.

Thanks !

Answer

This article describes a couple of examples on how to configure your webserver to route all requests through app.php with clean URL's: http://symfony.com/doc/2.8/cookbook/configuration/web_server_configuration.html

In your case your virtual host should look something like:

<VirtualHost *:9999>    
    DocumentRoot /var/www/SuperSwungBall/web
    <Directory /var/www/SuperSwungBall/web>
        AllowOverride None
        Order Allow,Deny
        Allow from All

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

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeScript assets
    # <Directory /var/www/project>
    #     Options FollowSymlinks
    # </Directory>

    <Directory /var/www/SuperSwungBall/web/bundles>
        <IfModule mod_rewrite.c>
            RewriteEngine Off
        </IfModule>
    </Directory>
    ErrorLog /var/log/apache2/project_error.log
    CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>