用的.htaccess和重写规则问题

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

我有网址的如游戏/的Xbox / 2 2是页码我需要的URL重写。这是我使用的是什么:

I have url's like games/xbox/2 2 being the page number I need the url rewritten. This is what I'm using:

RewriteRule games/(.*?)/$ games/consoles.php?console=$1 RewriteRule games/(.+?)/(.+?)/$ games/consoles.php?console=$1&page=$2

第一条规则工作正常,但第二个是返回的Xbox consoles.php为$ 1,而不是

The first rule works fine but the second is returning consoles.php as $1 instead of xbox

推荐答案

试着这么做:

RewriteRule games/([^/]+)/([^/]+)/?$ games/consoles.php?console=$1&page=$2 [L] RewriteRule games/([^/]+)/?$ games/consoles.php?console=$1 [L]

我第一次把你的最具体的规则先 - 这样,你不这样做一般的比赛,那么以后的更具体的比赛轧液,通用重写

I first put your most specific rule first - that way you don't do a general match, then a later more specific match mangles that general rewrite.

我还指定了 [L] 标志来表示要在发动机停止寻找在这一点上更多的比赛。重新排序规则是多余的在这种情况下,因为 [L] 标志,但它是一个很好的做法就可以进入。

I also specified the [L] flag to signify that you want the engine to stop looking for more matches at this point. Re-ordering the rules is redundant in this case because of the [L] flag, but it's a good practice to get into.

我也改变了前pressions咯。而不是使用([A-ZA-Z0-9] +)像previous海报说,我把它改为([^ /] +),因为这将匹配一切,但一个斜线,这样你就可以有怪异的控制台或游戏的名称。如果你想更具体的随意,但这种方式提供了最普通的用例。

I also changed the expressions slightly. Rather than using ([A-Za-z0-9]+) like the previous poster said, I changed it to ([^/]+) because that will match everything but a slash, so you can have weird console or game names. If you want to make it more specific feel free to, but this way provides the most general use-case.

更多推荐

用的.htaccess和重写规则问题

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

发布评论

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

>www.elefans.com

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