2013-07-23 36 views
1

我有一個非常大的論壇(230k線程,300萬個帖子),有大量404個網頁在Google網站管理員工具中報告,大約有14,000個404 URL。谷歌可能會顯示這些404,因爲我有傳入鏈接,這意味着我失去了很多搜索引擎優化的好處,因爲沒有這些鏈接跟隨到實際頁面。如何使用htaccess解決這些vbulletin 404錯誤?

我知道爲什麼我有這個問題,一年前在我的網站的網址是讓他們看起來像這樣改回vBulletin默認:

http://www.domain.com/showthread.php?t=323653&p=4230256 

我想保持他們,因爲這樣一來他們一年來一直如此。問題是,有兩個以前的格式都出現404錯誤:

這些:

http://www.domain.com/forums/showthread.php?t=21461 

http://www.domain.com/forums/showthread.php?t=16187 

其中只需要有forums/從網址中移除,而這些:

http://www.domain.com/forums/f8/39840-infractions_system_how_works.html 

http://www.domain.com/forums/f11/67410-viewing_ijji_gunz_replays_while_offline.html 

哪是一個時髦的URL結構,當我安裝了vbSEO時創建了它。

/forums/需要刪除,我認爲數字39840和67410可能是線程ID。我認爲在URL中我們需要重寫所有內容,但我並不完全確定如何使用htaccess來實現它。

回答

1

假設,你.htaccess位於網站根目錄 「/」

RewriteEngine on 
RewriteBase/

# removes "forums/" 
RewriteCond %{REQUEST_URI} !^/showthread.php$ [NC] 
RewriteRule ^forums/([^/]+)$ $1 [R=301,NC,L] 

# parses thread id 
RewriteCond %{REQUEST_URI} !^/showthread.php$ [NC] 
RewriteRule ^forums/[^/]+/(\d+)-.*$ showthread.php?t=$1 [R=301,NC,L] 
1

啓用mod_rewrite的,並通過httpd.conf的.htaccess,然後把這個代碼在你.htaccessDOCUMENT_ROOT目錄:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

# to redirect /forums/f8/39840-something.html to 
# /showthread.php?t=39840 
RewriteRule ^forums/[^/]+/([^-]+)-[^.]+\.html$ /showthread.php?t=$1 [R=301,NC,L,QSA] 

# to redirect /forums//showthread.php?t=39840 to 
# /showthread.php?t=39840 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^forums/([^/]+)/?$ /$1 [R=301,NC,L]