VirtualHost rewrite rules for Silex

After seeing Igor Wiedler's presentation on symfony Day I really wanted to try SIlex. It's a PHP micro-framework that seems especially well-suited for creating small sites and API's.

The Silex documentation lists the Apache rewrite rules when using a .htaccess file:


<IfModule mod_rewrite.c>
  Options -MultiViews
  RewriteEngine On
  #RewriteBase /path/to/app
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [L]
</IfModule>

But if possible, I put the Apache rewrite rules into the VirtualHost configuration. This requires to change the rules a bit. Namely adding a slash to index.php.

VirtualHost settings:


  Options -MultiViews
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ /index.php [L]

So I hope this will be useful to someone. Happy coding!