【发布时间】:2013-03-04 01:37:45
【问题描述】:
我的网站网址是www.testing.com,还有另一个网站www.testing.com/newsite。
我希望所有点击www.testing.com/newsite 的人都被重定向到www.newsite.com
【问题讨论】:
我的网站网址是www.testing.com,还有另一个网站www.testing.com/newsite。
我希望所有点击www.testing.com/newsite 的人都被重定向到www.newsite.com
【问题讨论】:
所以只需在索引页添加以下行。
header("Location: http://www.testing.com", false, 301);
exit;
或将其写入每个页面中包含的通用文件中。
确保标题位置中有http://,否则它将查找目录。
还要在末尾加上exit;,这样其他代码就不会执行了。
因为发送标头不会终止脚本执行。
--编辑-- 应该是301才能让它永远持续下去
【讨论】:
如果您有一个目录/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]
【讨论】:
/newsite 目录中
【讨论】:
在 htaccess 中使用它
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^newsite.*$ http://www.testing.com/ [R=301,L]
【讨论】: