for the project we have to set several PHP values with respect to the atmosphere (development/production), most particularly session save path plus some tracing and profiling configurations.

We don't want to create them within the PHP script because because of some horrible legacy code which may require lots of changes and that we don't wish to need to alter the .htaccess each time before commiting it to git (but we require .htaccess to stay in source control).

Can there be any method of doing something similar to this within the .htaccess:

if (hostname == "dev.example.com") {
  php_value session.save_path /tmp
  [...]
}

You are able to define rules in Apache's virtualhost config (a measure above .htaccess, you will need to request webmaster to edit this):

<VirtualHost *:80>                                                              
    ServerName piskvor.example.com
    ServerAlias *.host2.example.com
    php_value session.save_path /home/piskvor/tmp
</VirtualHost>
<VirtualHost *:80>                                                              
    ServerName someotherhost.example.org
    php_value session.save_path /tmp
</VirtualHost>

This provides the possible ways to configure each host in a different way (by hostname or perhaps a hostname wildcard). Most more recent Apache configurations support this.

In a previous job we used used the next:

<IfDefine SERVER1>
  php_value session.save_path /tmp1
</IfDefine>

<IfDefine SERVER2>
  php_value session.save_path /tmp2
</IfDefine>

You'd then starup apache using the additional switch:

-D SERVER1 SERVER2

EDIT:

EDIT

Maybe something similar to the next might be a middle-ground?

if (!file_exists('.htaccess')) {

  copy('.htaccess.default', '.htaccess');

  $handle = fopen('.htaccess', 'a');

  switch ($_SERVER['HTTP_HOST']) {

    case 'dev.site':
        fwrite($handle, 'php_value .....' . "\n");
        fwrite($handle, 'php_value .....' . "\n");
    break;

    case 'live.site':
        fwrite($handle, 'php_value .....' . "\n");
        fwrite($handle, 'php_value .....' . "\n");
    break;  

  }

  fclose($handle);

}