Rewrite with multiple parameters!?

I’m trying to get this to work but with no luck?

I have this url:
[noparse]www.mypage.com/cms/index.php?title=oakhill&page=start[/noparse]

And I want it to end up like this:
[noparse]www.mypage.com/cms/oakhill/start[/noparse]

I’m trying with this and it works with the first parameter (title) but not with the second… It then comes up with an Page is not found…
RewriteRule ^cms/([A-Za-z0-9_]+)(/([0-9]+))?/?$ cms/index.php?title=$1&page=$2 [L]

What am I doing wrong???

Thanks in advance!

Two things actually:

  1. ([0-9]+) only matches 1 or more digits, so it will not match “start”. Change it to ([A-Za-z0-9]+) like the first one
  2. You have three sets of parentheses in there
  • ([A-Za-z0-9_]+) – that’s $1
  • (/([A-Za-z0-9_]+)) was: (/([0-9]+)) – that’s $2
  • ([A-Za-z0-9_]+) was: ([0-9]+) – that’s $3

So you want $3 in your rule, which excludes the / instead of $2 which includes the slash.

Alternatively you could write it like this, which I personally find a bit more clean


RewriteRule ^cms/([A-Za-z0-9_]+)/?([A-Za-z0-9_]*)/?$ cms/index.php?title=$1&page=$2 [L]

So now you actually can use $2 because there are no nested backreferences anymore.

Thanks… That did the job :slight_smile: