2011-12-27 46 views
1

我需要幫助我的網站htaccess URL重寫。.htaccess站點重定向規則

問題是,某個類別的第一頁有好的無殘留URL,所有其他頁面都有髒網址。

例如第一頁有這樣的鏈接:

http://www.my-site-name.com/Category-name/Subcategory-name/ 

但第2頁,以及任何其他頁面是這樣的:

http://www.my-site-name.com/showcat.php?cat=Category-name&subcat=Subcategory-name&page=2 
http://www.my-site-name.com/showcat.php?cat=Category-name&subcat=Subcategory-name&page=3 

所以,我需要一些搜索引擎友好的htaccess的重定向規則使網址是這樣的:

http://www.my-site-name.com/Category-name/Subcategory-name-page-X/ 

或類似這樣的

http://www.my-site-name.com/Category-name/Subcategory-name/X/ 

但是可能我想再多一次。

這是的.htaccess的一部分爲:(我只是添加了完整的內容,也許有關於它的更多的東西

## For top rated items 
RewriteRule ^top/page/(.*)/$ top.php?page=$1 [L] 

## For latest items 
RewriteRule ^latest/recent-page-(.*)/$ latest.php?page=$1 [L] 

## For show most rated - most clicked - most downloaded and most searched items 
RewriteRule ^most-rated.html$ showmost.php?type=1 [L] 
RewriteRule ^most-clicked.html$ showmost.php?type=2 [L] 
RewriteRule ^most-downloaded.html$ showmost.php?type=3 [L] 
RewriteRule ^most-Searched.html$ showmost.php?type=4 [L] 

## For showing category of item 
RewriteRule ^(.*)/$ showcat.php?cat=$1 [L] 

## For showing subcategory of item 
RewriteRule ^(.*)/(.*)/$ showcat.php?cat=$1&subcat=$2 [L] 

## For showig item 
RewriteRule ^(.*)/(.*)/(.*).html$ show.php?cat=$1&sub_cat=$2&img=$3&rewrite=true [L] 

## this section should be inserted just after the showing item rule above 
#if the query string has cat, sub_cat and Img 
RewriteCond %{QUERY_STRING} ^cat=(.+)&sub_cat=(.+)&img=(.+)$ [NC] 
#and it is for resource show.php, then 301 redirect to Keyword rich URL 
RewriteRule ^show\.php$ http://www.my-site-name.com/%1/%2/%3.html? [NC,L,R=301] 
+0

。我是新手,請告訴我如何接受正確的答案,我該怎麼辦? – 2011-12-27 19:08:25

+2

答案左邊有一個灰色的複選標記,只需點擊回答您問題的問題旁邊的那個(最好) – Gerben 2011-12-27 19:28:12

回答

2

我也清理了一點點

#don't rewrite if file or dir exists 
RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule .* - [L] 

## For showing category of item 
RewriteRule ^([^/]*)/$ showcat.php?cat=$1 [L] 

## For showing paged subcategory of item 
RewriteRule ^([^/]*)/([^/]*)-page-([0-9]+)/$ showcat.php?cat=$1&subcat=$2&page=$3 [L] 

## For showing subcategory of item 
RewriteRule ^([^/]*)/([^/]*)/$ showcat.php?cat=$1&subcat=$2&page=1 [L] 

## For showig item 
RewriteRule ^([^/]*)/([^/]*)/([^/]*).html$ show.php?cat=$1&sub_cat=$2&img=$3&rewrite=true [L] 
+0

這是相同的, 它的工作原理相同。 – 2011-12-29 19:10:17

+0

@ user1038179你是什麼意思?第三條規則應該做你想要的。 – Gerben 2011-12-29 20:16:21

+0

我剛剛爲我的CMS添加了完整的.htaccess代碼,也許它會告訴你更多。我也試過你的答案,但URLs是相同的,我仍然沒有漂亮的網址。我還有這個:'http://www.my-site-name.com/showcat.php?cat = Category-name&subcat = Subcategory-name&page = 2' – 2011-12-31 18:18:31