jmansa
June 29, 2011, 8:58pm
1
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!
rpkamp
June 29, 2011, 9:45pm
2
Two things actually:
([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
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.