user75898
user75898

Reputation: 273

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

Upvotes: 0

Views: 909

Answers (2)

thomasfedb
thomasfedb

Reputation: 5983

If the '?' is causing troubles then try:

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

Upvotes: 0

David Wolever
David Wolever

Reputation: 154682

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

Upvotes: 1

Related Questions