第一种方法 添加一个index.html php 智能404跳转代码,适合换域名没改变目录的网站 适合于换域名,但是目录没有改变的网站.也可以用做301定向.转自于落伍 代码如下:复制代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>404</title> <meta http-equiv='refresh' content='5; url=http://www.jb51.net<?=$_SERVER[REQUEST_URI]?>'> </head> <body> 本站起用新域名访问 你目前访问的页面是http://www.jb51.cn<?=$_SERVER['REQUEST_URI']?> 系统为你重新定向到新站相应的页面http://www.jb51.net<?=$_SERVER['REQUEST_URI']?> 或等待5秒后,系统自动跳转到新站相应的页面 </body> </html>
第二种方法 Apache主机修改.htaccess实现跳转
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
第三种方法 适用于不支持.htaccess 的Nginx主机 在.conf配置文件中添加下面的语句:
if ($host = 'old.com' ) {
rewrite ^/(.*)$ http://www.new.com/$1 permanent;
}
三种方法都可以达到访问旧内容页直接跳转到新网站的确切页面,而非一般跳转的到首页。
<hr>
利用.htaccess将泛二级域名重定向到带www的主域名:
RewriteCond %{HTTP_HOST} ^.*.www.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^[a-vx-z0-9\.\_\-]*.domain.com$ [NC]
Rewriterule ^(.*)$ http://www.domain.com/$1 [L,R=301]这样一来,所有*.domain.com的二级域名,都会重定向到主域名www.domain.com,这样的好处是将泛解析规范化,不会造成权重分散,但坏处是就不能做二级域名了。