URL regex with optional params
I am working on URL re-writing with regex. I have a few scenarios of
/register
/register?x=1/register/
/register/?x=1开发者_如何学运维Currently I have ^/(.*)/(\?.+)$
but it is not correct
The last part should be optional, but not repeatable.
^/(.+)/?(\?.+)?$
gpojd was close.
You may also want to specify the URL contents, and make sure they're not empty:
^/\w+/?(\?\w+=\w+)?$
精彩评论