开发者

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+)?$
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜