Dear All, trying to figure out this but no luck.
Want to rewrite and beautify this specific ...?ln=zh-CN to /cn/... With the help of a genius @ StackOverflow(Laurence Gonsalves) im almost there! But stuck here:

/it/somepage goes nicely /somepage?ln=it
/de/somepage goes nicely /somepage?ln=de
/fr/somepage goes nicely /somepage?ln=fr
/cn/somepage but this gives 404 error!
/somepage?ln=zh-CN works ofcourse fine

# exception for Chinese version /cn/somepage
RewriteRule ^zh-CN/(.*) /$2?ln=zh-CN [L]
RewriteRule ^cn/(.*) /$2?ln=zh-CN [L]

# redirect all /XX/somepage goes to /somepage?ln=XX
RewriteRule ^([a-z][a-z])/(.*) /$2?ln=$1 [L]

The second part works perfectly! The first part doesnt do the work well for that one and only exception zh-CN... What is being overlooked here? All clues or tips will be blessed with feminine attentions in our afterlife, i'm so sure!

link|improve this question

feedback

1 Answer

up vote 2 down vote accepted

If I read that right, replace $2 in the first two rules with $1.

Explanation: You've only one set of brackets in the match, so the backreference $2 is undefined (and will expand to an empty string, hence the 404), whereas $1 will contain the text matched by (.*)

link|improve this answer
That was IT, now it works. Long live opensource communities. Also i now understand why it didnt work before. Thanks very much! – Sam Dec 2 '10 at 18:31
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.