让我们拿下面的图像为例。问题是3个url地址指向同一个服务器,我需要创建一个从一个到另一个的301 redirect,主要是因为SEO的原因。但是我不能在htaccess中这样做,因为它为其中一个域创建了一个无穷大循环,我还尝试了这样的方法:
if ($do_redirect !== '' && trim($do_redirect,'/') !== trim($userrequest,'/')) {
if (strpos($do_redirect,'/') === 0){
$do_redirect = home_url().$do_redirect;
}
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: ' . $do_redirect);
exit();
}但是从理论上讲,这应该是可行的,但是当我使用curl -I domain.com检查这样的域时,我得到了:
HTTP/1.1 200正常 日期:2014年11月25日,星期二13:33:49
而不是:
HTTP/1.1 301永久移动 日期:2014年11月25日,星期二13:33:04
有什么想法吗?

发布于 2014-11-25 14:05:13
最好的解决方案是在Apache端这样做。
<VirtualHost *:80>
ServerName sample.org
Redirect 301 / http://www.newdomain.com/
</VirtualHost>Apache将以这种方式以较低的开销发布301。如果您不能这样做,PHP解决方案看起来就像
if($_SERVER['HTTP_HOST'] == 'sample.org') {
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: http://www.newdomain.com/');
exit();
}https://stackoverflow.com/questions/27128175
复制相似问题