Regex to Match Anything but the Number 23, isapai rewrite

Hello

I am trying to write a regular expression like the following to redirect query string id to 23 if it receives anything but 23:

RewriteRule ^manual-treadmill.aspx\?ID=[^23]+.* manual-treadmill.aspx?ID=23 [NC,O,R=301]

It works great unless they put a number that starts with a two or three. So it is basically breaking if they put:

2
3
32
233

but it works if they put
1
4
5
6
7
8
9
23
11
41
51
61
71
81
91
etc.

Can someone please tell me how to update this only redirects if they don't put 23 in that order?

Thanks in advance,
Shawn
smowerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ozoConnect With a Mentor Commented:
Sorry, I thought you only needed a match, not a capture.
You can make the ...+ the first option:
(...+|.?$|[^2][^3])
Or, since http://www.regexr.com/ supports (!?)
(?!23$)(.*)
0
 
ozoCommented:
If you want to redirect query string id to 23 if it receives anything but 23, why not redirect everything to 23 and use RewriteCond to skip the rule if it is already 23?
0
 
smowerAuthor Commented:
Not sure how to do that. I have very limited understanding of ISAPI rewrite. I have a slight knowledge of regular expressions but I was trying to figure out how to do the regular expression to find any query ID except for 23.
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
ozoCommented:
if your regular expression engine does not support (?!) then you might use (.?$|[^2][^3]|...)
0
 
smowerAuthor Commented:
Thanks, that fixes the few example numbers but is still not quite getting everything for example
123
2333
-123
322

I need it to capture everything except 23 only.

Thank you,
Shawn
0
 
ozoCommented:
I don't know why 123 and 322 would not match, but if the expression is anchored, you may have to change ... to ...+
0
 
smowerAuthor Commented:
^manual-treadmill.aspx\?ID=(.?$|[^2][^3]|...+)

it's still not working for me. I am testing it on:
http://www.regexr.com/
0
 
ozoCommented:
In what way is it not working?  It seems to do what I expect.

By the way http://www.regexr.com/ seems to support (?!23)
0
 
smowerAuthor Commented:
it only partially matches. For example:
123 or 1234 or 12345  or 123456 or '123 or 123" or -123 or 123- etc. - only catches the first couple numbers or characters.
33 doesn't get captured
22 doesn't get captured
anyway these are just a couple of examples. I need it to capture everything except 23 exactly.
0
 
smowerAuthor Commented:
Awesome, thank you so much.  This one worked!: (?!23$)(.*)

the other one mostly worked: (...+|.?$|[^2][^3])
However it would still have issues with:
33
20
21
22
24
25
26
27
28
29

but since the other one works I will just use that.
Thank you!
Shawn
0
 
smowerAuthor Commented:
(?!23$)(.*)  works.
(...+|.?$|[^2][^3]) partially works.
0
All Courses

From novice to tech pro — start learning today.