前段時間由於網站發展需要,將論壇從原主站子目錄中獨立出來,原來的域名 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. |