.htaccess regex rewrite rule

2019-08-29 02:53发布

I have the following regex:

RewriteRule ^blogs/([^/]*)/([^/]*) blogs/index.php?blogger=$1&blog=$2

This works fine for the following cases:

however it does not handle:

How can I make the "/" separator optional in this regex?

2条回答
smile是对你的礼貌
2楼-- · 2019-08-29 03:28

I'd use:

^blogs/([^/]*)(/([^/]*))?

And you'd just have to check and make sure that $2 is still correct (with the two capture groups, it might be $3… I can't remember).

查看更多
淡お忘
3楼-- · 2019-08-29 03:33

If the '?' is causing troubles then try:

^blogs/([^/]*)(/([^/]*)){0,1}
查看更多
登录 后发表回答