我需要帮助我的网站重写htaccess URL。
问题是,某个类别中的第一页只有漂亮的免费URL,而其他所有页面都有脏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
所以,我需要一些SEO友好的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 :(得分: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]