前段时间由于网站发展需要,将论坛从原主站子目录中独立出来,原来的域名 http://www.***.com/bbs 更换为 http://bbs.***.com,为了保证原有良好收录和权重 (PR 为 5),也保证原有地址可以访问,所以需要想办法在不被判为作弊的情况下将原有论坛中每个页面的地址转向到对应新地址。
开始没有想到直接在服务器上设置 301 转向,而是通过对 404 页面来路的分析进行了这样的设置:用 PHP 做页面如 error.php,然后定义出错 404 转向页为 error.php,然后在 error.php 中用 $_SERVER[‘QUERY_STRING’]; 获取出错来路中的字符串 (其中包含你原来的访问地址),然后再用字符串替换函数替换成新的就行了。这样论坛访问地址由 http://www.***.com/bbs 完全转化为 http://bbs.***com 访问,并且保证用户通过原链接如
http://www.***.com/bbs/thread-1-236598-1.html 可正常跳转到对应新域名,error.php 页面代码如下:
PHP 代码
以下为引用的内容:
|
前天在 DISCUZ 论坛看到有朋友说要换地址,想做 301 转向的,这才仔细研究了下 301 转向的问题,发现其实之前走了弯路,
直接用 301 永久转向就行了,况且 GOOGLE 网站管理员帮助文件中也说明了 301 转向是可行的:
XML/HTML 代码
以下为引用的内容:来源:http://www.google.com/support/webmasters/bin/answer.py?hl=enanswer=93633
If you need to change the URL of a page as it is shown in search engine results, we recommended that you use a server-side 301 redirect. This is the best way to ensure that users and search engines are directed to the correct page. The 301 status code means that a page has permanently moved to a new location. 301 redirects are particularly useful in the following circumstances: You‘ve moved your site to a new domain, and you want to make the transition as seamless as possible. People access your site through several different URLs. If, for example, your home page can be reached in multiple ways - for instance, http://example.com/home, http://home.example.com, or http://www.example.com - it’s a good idea to pick one of those URLs as your preferred(canonical)destination, and use 301 redirects to send traffic from the other URLs to your preferred URL. You can also use Webmaster Tools to set your preferred domain. You‘re merging two websites and want to make sure that links to outdated URLs are redirected to the correct pages. |