4

我的网站网址是www.testing.com,还有另一个网站www.testing.com/newsite

我希望所有点击www.testing.com/newsite的人都被重定向到www.newsite.com

4

4 回答 4

5

所以只需在索引页面添加以下行。

header("Location: http://www.testing.com", false, 301);
exit;

或者将其写入每个页面中包含的通用文件中。

确保http://在标题位置,否则它将寻找目录。

并放在exit;最后,这样其他代码就不会执行。

因为发送标头不会终止脚本执行。

--EDIT-- 它应该是 301 让它永远持续下去

于 2013-03-15T11:05:29.360 回答
2

如果您有一个目录/newsite,则在该目录中放置一个.htaccess

RewriteEngine On
RewriteRule ^.*$ http://www.newsite.com/ [R=301,L] 

但是,如果您将其定向newsite.com/newsite目录中,那么您需要Sankalp Mishra在他的回答中所写的内容。(但使用newsite而不是testing

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^newsite$ http://www.newsite.com/ [R=301,L]
于 2013-03-15T11:07:08.860 回答
0

像这样写标题:

  header("Location: http://www.testing.com"); 

在http://www.testing.com/newsite的主页上

有关标题的更多信息

于 2013-03-15T11:06:13.587 回答
0

在 htaccess 中使用它

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^newsite.*$ http://www.testing.com/ [R=301,L]
于 2013-03-15T11:07:16.990 回答