如果一个网站拥有两个域名:domain1.com和domain2.com。
在网站运营前期,主推domain1.com,但发展到中期,由于品牌或产品定位的原因,domain1.com这个域名不再适合当前情况,要更换成domain2.com。
作为SEO,我们肯定推荐使用301跳转,当用户访问domain1.com时,自动引导用户进入新域名domain2.com,可以通过程序或域名跳转实现301跳转,这样可以将旧域名PR传递到新域名。
但是如果用户收藏了旧域名的某个内容页(譬如:domain1.com/content/20070808.html),通过域名跳转直接引导到domain2.com首页恐怕会产生较差用户体验,特别是对未及时获知域名更换的用户;最好方式是实现通配,动态的将旧域名某个内页跳转到新域名相同页面的URL,那如何用技术手段实现新旧内页URL之间的301跳转???
即:从domain1.com/content/20070808.html跳转到domain2.com/content/20070808.html,并使浏览器返回301代码
例如:
大旗网域名由chinabbs.com换成daqi.com
博客网域名由blogchina.com换成bokee.com
有兴趣或者有解决办法的程序员,请留下你的联系方式或者发表评论,一起探讨下关于URL重定向的相关问题。
感谢dawnh的提示,我有点恍然大悟,PHP下的实现方式(参考):
.htaccess文件代码如下(bloghuman.com的.htaccess如此设置):
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^bloghuman.com [nc]
rewriterule ^(.*)$ http://www.bloghuman.com/$1 [r=301,nc]
RewriteEngine on
rewritecond %{http_host} ^bloghuman.com [nc]
rewriterule ^(.*)$ http://www.bloghuman.com/$1 [r=301,nc]
注释1:如果用户访问http://bloghuman.com/,则跳转至http://www.bloghuman.com,且返回301状态码;当用户访问http://bloghuman.com/post/301.htm,则跳转至http://www.bloghuman.com/post/301.htm,并返回301状态码。
注释2:测试URL:http://www.wlxs.com.cn/,你可以访问http://www.wlxs.com.cn/post/301.htm
我在wlxs.com.cn下配置了.htaccess文件,使其301跳转至http://www.bloghuman.com/post/301.htm
我的.htaccess配置实现了由主域名(bloghuman.com)301跳转至二级域名(www.bloghuman.com);
结论:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^www.domain1.com [nc]
rewriterule ^(.*)$ http://www.domain2.com/$1 [r=301,nc]
RewriteEngine on
rewritecond %{http_host} ^www.domain1.com [nc]
rewriterule ^(.*)$ http://www.domain2.com/$1 [r=301,nc]
感谢shiny的反复提示,ASP脚本实现301跳转的方法:
<%
if request.ServerVariables("HTTP_HOST")="domain1.com" or request.ServerVariables("HTTP_HOST")="www.domain1.com" then
if Request.ServerVariables("QUERY_STRING")<>"" then p="?"
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.domain2.com"&Request.ServerVariables("SCRIPT_NAME")&p&Request.ServerVariables("QUERY_STRING")
Response.End
end if
%>
if request.ServerVariables("HTTP_HOST")="domain1.com" or request.ServerVariables("HTTP_HOST")="www.domain1.com" then
if Request.ServerVariables("QUERY_STRING")<>"" then p="?"
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.domain2.com"&Request.ServerVariables("SCRIPT_NAME")&p&Request.ServerVariables("QUERY_STRING")
Response.End
end if
%>
相关日志
桥页SEO:网站自我毁灭工具
如何查询绑定于同一IP下的网站域名?(IP反查询域名工具推荐)
《Google官方SEO入门指南》十四: 对网站管理员有用的资源(完)
《Google官方SEO入门指南》十三:充分利用网站分析工具
《Google官方SEO入门指南》十二:充分利用免费的网站管理员工具
《Google官方SEO入门指南》十一:以恰当的方式推广你的网站
《Google官方SEO入门指南》十:为链接添加nofollow属性
《Google官方SEO入门指南》九:有效使用robots.txt
《Google官方SEO入门指南》八:网页图片优化
《Google官方SEO入门指南》七:合理应用heading标签
桥页SEO:网站自我毁灭工具
如何查询绑定于同一IP下的网站域名?(IP反查询域名工具推荐)
《Google官方SEO入门指南》十四: 对网站管理员有用的资源(完)
《Google官方SEO入门指南》十三:充分利用网站分析工具
《Google官方SEO入门指南》十二:充分利用免费的网站管理员工具
《Google官方SEO入门指南》十一:以恰当的方式推广你的网站
《Google官方SEO入门指南》十:为链接添加nofollow属性
《Google官方SEO入门指南》九:有效使用robots.txt
《Google官方SEO入门指南》八:网页图片优化
《Google官方SEO入门指南》七:合理应用heading标签
最后编辑: 黑色梦中 编辑于2007/12/20 09:23
Matt Cutts给Wordpress博客系统
WordPress SEO Tips For B
2007/08/13 13:35 | by























boblog程序,我想xxx.com301到www.xxx.com如何实现,需要改那几个文件呀?
用这个代码可以实现吗?
<? Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.xxx.com" );?>
万分感谢!
我想通过加代码的方式实现301转向,好难呀
支持下链接http://www.lanlansky.cn
我以前用的域名是http://www.jsjay.com 现在用的是http://www.ie92.com 可以在百度或者谷歌搜索大闷锅 看看··我的站是个论坛PR3 IE92域名PR是三 现在JSJAY这个玉米我没有绑定··只是解析过去··但是不能访问
我现在不知道怎么办 希望大家能帮我看看··我的QQ351675665
跳转得好好用才行
我有另一个问题:如a.com和a.com/index.asp,都是一个主页,但后者PR2,前者PR0,我需要把后者跳转到前者,即不带index.asp的,请问如何跳呢……
我这里也有篇301跳转的,但没有找到解决方法:http://www.piaoyi.org/seo/HTTP-Header-301-Moved-Permanently.html,请指教~
就是说要怎么操作呢。