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?
我有一个子域ABC.mydomain.com,其$ _SERVER ['HTTP_HOST']我想更改为另一个域anotherdomain.com。 Anotherdomain.com也是我拥有的。是否可以使用.htaccess全局更改此变量($ _SERVER ['HTTP_HOST'])?如果是这样,怎么样?
2 个解决方案
#1
7
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),但我会尝试这样做:
# .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.
它通过Laravel框架引起了我的一些问题,但它适用于一个简单的网站......所以我会试一试。
#2
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:
您无法使用.htaccess更改$ _SERVER变量,因为您可以在那里阅读http://httpd.apache.org/docs/2.2/howto/htaccess.html。我认为您真正的需要是将页面重定向到新域。尝试在.htaccess文件中添加此行:
Redirect 301 ABC.mydomain.com http://example.com/newdirectory/
重定向301 ABC.mydomain.com http://example.com/newdirectory/
#1
7
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),但我会尝试这样做:
# .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.
它通过Laravel框架引起了我的一些问题,但它适用于一个简单的网站......所以我会试一试。
#2
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:
您无法使用.htaccess更改$ _SERVER变量,因为您可以在那里阅读http://httpd.apache.org/docs/2.2/howto/htaccess.html。我认为您真正的需要是将页面重定向到新域。尝试在.htaccess文件中添加此行:
Redirect 301 ABC.mydomain.com http://example.com/newdirectory/
重定向301 ABC.mydomain.com http://example.com/newdirectory/