是不是看不懂了?
那么这样说吧.比如1ting.com是个IIS下的独立站点,和www.1ting.com是不同的.而且1ting.com没有rewrite之类的,只能运行php.那么怎么实现访问1ting.com/xxx.html时候直接跳转到www.1ting.com/xxx.html.光总想了一个办法:自定义404页面,然后用404页面来301转向.
404页面的代码:
<?php
$request_uri = isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : '';
$redirect_uri = sprintf('http://www.1ting.com%s',$request_uri);
header( "HTTP/1.1 301 Moved Permanently" );
header( "content-type: text/html;charset=UTF-8" );
header('Status: 301 Moved Permanently');
header(sprintf('Location: %s',$redirect_uri) );
echo ('<a href="' .$redirect_uri . '">The page you are looking for has moved to ' .$redirect_uri . '</a>');
?>
用这段代码就能实现了.当然还可以重定向到别的上去.但是返回的状态码是404先.
还有,别他妈跟我讲SEO了,这个是给人看的.


