I'm trying to rewrite urls to allow only numbers and (optionally) the word "all" comma separated.
我正在尝试重写网址,只允许数字和(可选)单词“all”逗号分隔。
For example, something like this: mypage/23,15,all,2,all
例如,像这样:mypage / 23,15,all,2,all
I tried something, but there is a problem. First, this is my rule (probably syntatically wrong):
我尝试了一些东西,但是有一个问题。首先,这是我的规则(可能是语法错误):
mypage/([\d,?(all)]+)
The problem here is that if a write mypage/23 works (correct), mypage/23,all works (correct), mypage/23,all,a works (because it detects 'a' of 'all', so wrong)
这里的问题是,如果写mypage / 23工作(正确),mypage / 23,所有工作(正确),mypage / 23,all,a works(因为它检测'a'为'all',所以错误)
How can I modify the rule to accept only the entire word "all"?
如何修改规则以仅接受整个单词“all”?
Thank you.
2 个解决方案
#1
2
You can use this regex:
你可以使用这个正则表达式:
RewriteRule ^mypage/((?:\d+|all)(,(?:\d+|all))*)/?$ target-url?str=$1 [L,NC,QSA]
There is no grouping of characters inside character class i.e. [...]
字符类中没有字符分组,即[...]
#2
0
Try this: i think it should work
试试这个:我认为它应该有效
/([\d]+,(all)+)
[] for optional
() for grouping
#1
2
You can use this regex:
你可以使用这个正则表达式:
RewriteRule ^mypage/((?:\d+|all)(,(?:\d+|all))*)/?$ target-url?str=$1 [L,NC,QSA]
There is no grouping of characters inside character class i.e. [...]
字符类中没有字符分组,即[...]
#2
0
Try this: i think it should work
试试这个:我认为它应该有效
/([\d]+,(all)+)
[] for optional
() for grouping