We use the ExpressionEngine CMS (php) to create websites. For each site, we set up a subversion repository and commit the EE installation as well as any custom templates, images
We deal with this by maintaining a config-specific directory.
So, for instance if you have different .htaccess and config.php files between dev and production they would be maintained in /trunk/config/{environment}/
We use ant/nant scripts to create release packages, and the scripts have a build task for each environment. Those tasks pick up the config specific files.
--
Another commenter suggests to switch on HTTP_POST. Unfortunately I can't comment directly (not a high enough rep). Using HTTP_POST to determine environmental configuration has potential security issues since the value of this comes from the client.