问题:
如果一个网站拥有两个域名: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]


注释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]





感谢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
%>


SEO » SEO教程 | 评论(34) | 引用(0) | 阅读(9271)

oxygen
2007/08/13 15:13
正需要这个功能。。。不知道可有大侠能解决的。。。
Cloudream
2007/08/13 14:43
引入一段js判断一下 再显示tip就可以了……
黑色梦中 回复于 2007/08/14 09:35
JS可以实现返回301状态码吗?
huaxlee
2007/08/13 14:29
如果是apache主机的话,用.htaccess可以很简单地实现。
黑色梦中 回复于 2007/08/14 09:34
能否提供下具体的实现办法,我在服务器上做个测试,如果正确实现,我将公布给大家测试结果
EndTo
2007/08/13 14:13
我发现一个网站,赢在米坛就是这么改变了转向,现在是zunmi.com,你可以向这个站长咨询一下。
黑色梦中 回复于 2007/08/14 09:33
Thanks !!!
分页: 4/4 第一页 上页 1 2 3 4 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]