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?
Asked
Active
Viewed 1.2k times
6

samayo
- 16,163
- 12
- 91
- 106

Daniel Morgan
- 79
- 1
- 1
- 3
2 Answers
10
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.

Sam
- 20,096
- 2
- 45
- 71
-
You're incredible, thanks. It worked. – Daniel Morgan Jun 19 '13 at 02:22
1
You can't change the $_SERVER variable using .htaccess, as you can read there http://httpd.apache.org/docs/2.2/howto/htaccess.html. I think your real need is to redirect the page to a new domain. Try adding this line in you .htaccess file:
Redirect 301 ABC.mydomain.com http://example.com/newdirectory/

Lucas Maus
- 96
- 6