Maxime Bernard's blog

Rewrite on Symfony

Hi there ~~ I know it’s been a while, but I’m gonna try to write more articles now that I’m currently working at Smile.

Fabien Potencier, that you probably know, is the creator of the famous project Symfony. When he realized the Jobeet tutorial and all the tutorials you can find on Symfony-project.org, you’ll find this VirtualHost:

<VirtualHost 127.0.0.1:8080>
DocumentRoot "/home/sfproject/web"
DirectoryIndex index.php
<Directory "/home/sfproject/web">
AllowOverride All
Allow from All
</Directory>

Alias /sf /home/sfproject/lib/vendor/symfony/data/web/sf
<Directory "/home/sfproject/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>

As you can see, there is the line “AllowOverride All”. Usually, the Virtualhosts you’ll create by copy/paste the default VirtualHost will be “AllowOverride None”. Changing it to “All” is a very bad practice.

If you take a look to Apache’s documentation, you’ll read this:

When this directive is set to All, then any directive which has the .htaccess Context is allowed in .htaccess files.

If you want to optimize your website, it’s not recommend to do this because Apache will check every file in every directory.

The best practice is to use these simple RewriteRules:

    AllowOverride None

    Order allow,deny
    Allow from all

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^.*$ /index.php [L]

Try it, you’ll get better results.


  1. tanjona reblogged this from maximebernard
  2. maximebernard posted this
To Tumblr, Love PixelUnion