store constant variable on server via .htaccess
To make switching between hosts automatically You could use SetEnvIf :
.htaccess :
SetEnvIf Host host\.com INDEX_URL=http://host.com/index.php
SetEnvIf Host dev\.host\.com INDEX_URL=http://dev.host.com/index_dev.php
PHP :
$indexUrl = isset($_SERVER['INDEX_URL']) ? $_SERVER['INDEX_URL'] : '';
You can save it as environment variable. Put this in .htaccess:
SetEnv INDEX_URL http://example.com/index.php
And get it in PHP:
$indexUrl = getenv('INDEX_URL');