I am currently working as an independent developer on two projects using Symfony. This has been a great trip into a quite huge framework - and a great experience finally getting to know mod_rewrite a little better.
The first thing was that the urls in Symfony soon become something like this:
http://hostname/appname.php/modulename/actionname/arg1/arg1value/arg2/arg2value
Which was cool, but not as cool as if I could remove the ".php", hence I came up with:
.htaccess # xxxx.php -> xxxx (if the file does not exist)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\./]+)/(.*) $1.php/$2 [L]
This worked just fine!
One thing I had serious issues with was non-existing static resources. It boils down to Symfony thinking that every request for http://host/xxx/yyy/zzz is a call to action "zzz" on module "yyy" in application "xxx". This is because of this rule:
.htaccess # no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
In general this is perfectly smart, except when you try something along the lines of:
http://hostname/images/somefolder/mysuperimage.png (which does not exist)
Then symfony tries to execute the action "mysuperimage.png" on module "somefolder" in the application which you created first (typically called "frontend", and represented by "index.php"). This is down right annoying!
But there is an easy fix. All the php-files (two for each application, production/dev) are placed in the "web" folder directly. If all your resources are placed in subdirectories then all you have to do is tell mod_rewrite to leave these folders alone!
.htaccess # skip real folders
RewriteRule ^backend/.*$ - [PT]
RewriteRule ^css/.*$ - [PT]
RewriteRule ^images/.*$ - [PT]
RewriteRule ^resources/.*$ - [PT]
RewriteRule ^sfPropelPlugin/.*$ - [PT]
RewriteRule ^swf/.*$ - [PT]
In one place I had a lot of missing resources. I did not want to just give a flash-frontend a 404 so here was a quick fix for that:
.htaccess # Rewrite some resources to .xxx -> 404.xxx
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^resources/(.*).png resources/404.png [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^resources/(.*).jpg resources/404.jpg [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^resources/(.*).flv resources/404.flv [L]