对于网站的.htaccess重定向规则

编程入门 行业动态 更新时间:2024-10-20 16:37:50
本文介绍了对于网站的.htaccess重定向规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

www.my-site-name/Category-name/Subcategory-name/

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

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

所以,我需要一些搜索引擎友好的htaccess重定向规则作出的网址是这样的:

www.my-site-name/Category-name/Subcategory-name-page-X/

或像这样

www.my-site-name/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 $ www.my-site-name/%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:

www.my-site-name/Category-name/Subcategory-name/

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

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

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

www.my-site-name/Category-name/Subcategory-name-page-X/

or like this

www.my-site-name/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$ www.my-site-name/%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重定向规则

本文发布于:2023-11-01 18:14:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550052.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   规则   网站   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!