简体   繁体   中英

.htaccess regex rewrite rule

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?

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).

If the '?' is causing troubles then try:

^blogs/([^/]*)(/([^/]*)){0,1}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM