对于网站的.htaccess重定向规则 [英] .htaccess redirection rule for site

查看:110
本文介绍了对于网站的.htaccess重定向规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要htaccess的URL重写我的网站帮助。

问题是,在某些类别的只是第一页有很好的克鲁夫特免费网址,和所有其他网页有肮脏的网址。

例如第一页的链接是这样的:

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

但是2页,以及任何其他网页都是这样:

<$p$p><$c$c>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的一部分,认为:(我只是说全部内容,也许有关于它的更多的东西

  ##为最高评价的项目
重写规则^顶/页/(.*)/$ top.php?页= $ 1 [L]

##对于最新项目
重写规则^最新/近期页 - (。*)?/ $ latest.php页面= $ 1 [L]

##对于节目最受好评的 - 最点击 - 下载次数最多的和最搜寻的产品
重写规则^最rated.html $ showmost.php?类型= 1 [L]
重写规则^最clicked.html $ showmost.php?类型= 2 [L]
重写规则^最downloaded.html $ showmost.php?类型= 3 [L]
重写规则^最Searched.html $ showmost.php?类型= 4 [L]

##用于显示项目的类别
重写规则^(。*)/ $ showcat.php?猫= $ 1 [L]

##用于显示项目的子类别
(*)(。*)重写规则^ / / $ showcat.php猫= $ 1安培; subcat = $ 2 [L]

##对于showig项目
重写规则^ / / HTML $ show.php猫= $ 1安培(*)(*)(*);?sub_cat = $ 2及IMG = $ 3及重写=真[L]

##这一部分应该只是表现项目的规则后,上面插
#如果在查询字符串中有猫,sub_cat和图
的RewriteCond%{QUERY_STRING} ^猫=(+)及sub_cat =(+)及IMG =(+)$ [NC]
#,然后它是资源show.php,然后301重定向到关键字丰富的网址
重写规则^秀\的.php $ http://www.my-site-name.com/%1/%2/%3.html? [NC,L,R = 301]
 

解决方案

我还清理了一点点

如果文件或目录存在

 #不重写
的RewriteCond%{} REQUEST_FILENAME -D [OR]
的RewriteCond%{} REQUEST_FILENAME -f
重写规则。*  -  [L]

##用于显示项目的类别
重写规则^([^ /] *)/ $ showcat.php?猫= $ 1 [L]

##用于显示项目的寻呼子类别
重写规则^([^ /] *)/([^ /] *) - 页 - ([0-9] +)/ $ showcat.php猫= $ 1安培; subcat = $ 2及页= $ 3 [L]

##用于显示项目的子类别
重写规则^([^ /] *)/([^ /] *)/ $ showcat.php猫= $ 1和; subcat = $ 2及页= 1 [L]

##对于showig项目
重写规则^([^ /] *)/([^ /] *)/([^ /] *)HTML $ show.php猫= $ 1安培;?sub_cat = $ 2及IMG = $ 3及重写=真[L]
 

I need help with htaccess URL rewriting for my site.

Problem is that just first page in some category has nice cruft free URL, and all other pages has dirty URLs.

For example first page has link like this:

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

But page 2, and any other pages are like this:

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

So, I need some SEO friendly htaccess redirect rule to make URLs like this:

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

or like this

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

But probably I would like first more.

This is part of .htaccess for that: (I just added full content, maybe there is something more about it.

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

解决方案

I also cleaned it up a little

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

这篇关于对于网站的.htaccess重定向规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆