Is it possible to change the $_SERVER['HTTP_HOST'] in htaccess?

Daniel Morgan picture Daniel Morgan · Jun 19, 2013 · Viewed 11.1k times · Source

I have a sub-domain ABC.mydomain.com whose $_SERVER['HTTP_HOST'] I would like to change to another domain anotherdomain.com. Anotherdomain.com is one that I own too. Is it possible to globally change this variable ($_SERVER['HTTP_HOST']) using .htaccess? If so, how?

Answer

Sam picture Sam · Jun 19, 2013

Probably isn't the most convenient solution (not sure if there is a way to do this straight through .htaccess), but I would try this:

# .htaccess
php_value auto_prepend_file alter_host.php

# alter_host.php
<?php
    $_SERVER['HTTP_HOST'] = 'anotherdomain.com';
?>

It caused some issues with me through the Laravel framework, but it worked with a simple site..so I'd give it a go.