开发者

URL regex with optional params

开发者 https://www.devze.com 2023-04-04 18:33 出处:网络
I am working on URL re-writing with regex. I have a few scenarios of /register /register?x=1 /register/ /register/?x=1

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

精彩评论

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