Reputation: 11446
I have a web service that I have a rewrite on. I need to be able to allow hyphens or dash in the query. Here is my rewrite:
rewrite ^/app/api/sanction/([0-9]+)/athleteList/([a-zA-Z0-9,]+)/-([0-9,]+)$ /app/athleteList.phtml?s=$1&l=$2&c=$3 last;
The query works fine like this:
/app/api/sanction/35172/athleteList/MLEVEL07/25001,24450
However when I put a dash or hyphen here, the query will fail.
/app/api/sanction/35172/athleteList/MLEVEL-07/25001,24450
As you can see, I have the hyphen listed in the regex, unsure of what I may be doing wrong here...
Upvotes: 1
Views: 2205
Reputation: 4366
You should place the hyphen in the previous group :
([a-zA-Z0-9,-]+)/([0-9,]+)
This will, however, match "---1020-,-02-1-," and i'm not sure this is what you want. Hence my first proposition, corrected now:
([a-zA-Z0-9,]+)(-([0-9]+))?/-([0-9,]+)
This will match only "weofhw234fhweo,sdfsff3284982-20423400" and not "--,j2j,f9223-2-3402--0d-f0s-f"
Upvotes: 3
Reputation: 1761
I think you've misplaced the dash. It should be like this
rewrite ^/app/api/sanction/([0-9]+)/athleteList/([a-zA-Z0-9,-]+)/([0-9,]+)$ /app/athleteList.phtml?s=$1&l=$2&c=$3 last;
Note that "-" was moved from after "/" into inside brackets. If dash is the last character inside square brackets, it doesn't have a special meaning to mark a range of characters (like in a-z).
Upvotes: 1
Reputation: 270617
Just add a -
inside ([a-zA-Z0-9,-]+)
, at the end of the []
character class, and remove the hyphen after the next /
:
rewrite ^/app/api/sanction/([0-9]+)/athleteList/([a-zA-Z0-9,-]+)/([0-9,]+)$ /app/athleteList.phtml?s=$1&l=$2&c=$3 last;
#----------------------------------------------------------^^^^^^^^
Upvotes: 0