【问题标题】:.htaccess redirection rule for site.htaccess 网站重定向规则
【发布时间】:2011-12-27 18:51:21
【问题描述】:

我需要帮助我为我的网站重写 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 重定向规则来制作这样的 URL:

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]

【问题讨论】:

  • 我是新手。请告诉我如何才能接受正确答案,我该怎么办?
  • 答案左侧有一个灰色复选标记。只需点击回答您问题的问题旁边的问题(最佳)。

标签: .htaccess url


【解决方案1】:

我也清理了一下

#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]

【讨论】:

  • @user1038179 你是什么意思?第三条规则应该做你想做的。
  • 我刚刚为我的 CMS 添加了完整的 .htaccess 代码,也许它会告诉你更多信息。我也试过你的答案,但是 URL 是一样的,我仍然没有漂亮的 URL。我还有这个:http://www.my-site-name.com/showcat.php?cat=Category-name&subcat=Subcategory-name&page=2
猜你喜欢
  • 2011-07-17
  • 2019-09-01
  • 2017-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-22
相关资源
最近更新 更多