Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
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 (.*)

share|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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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