Theraloss
Theraloss

Reputation: 700

RewriteRule: Allow only numbers and a specific string comma separated

I'm trying to rewrite urls to allow only numbers and (optionally) the word "all" comma separated.

For example, something like this: 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)

How can I modify the rule to accept only the entire word "all"?

Thank you.

Upvotes: 1

Views: 313

Answers (2)

nammalvar 2.0
nammalvar 2.0

Reputation: 111

Try this: i think it should work

/([\d]+,(all)+)

[] for optional
() for grouping

Upvotes: 0

anubhava
anubhava

Reputation: 785146

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. [...]

Upvotes: 3

Related Questions