Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

am trying to write a redirect but as a green noob is tougher than i tought. What i want is: on the condition that there are No Specific Page in the url, but the language IS set, it to redirect to the home page of that language. First ill tell you the nature of current working site and the apache code that achieves that:

/it/somepage goes nicely /somepage?ln=it
/de/somepage goes nicely /somepage?ln=de
/fr/somepage goes nicely /somepage?ln=fr
/cn/somepage goes nicely /somepage?ln=cn

# WORKS beautifully
RewriteRule ^zh-CN/(.*) /$1?ln=zh-CN [L]
RewriteRule ^cn/(.*) /$1?ln=zh-CN [L]
RewriteRule ^([a-z][a-z])/(.*) /$2?ln=$1 [L]

Here, the 3rd line is the default redirect. The ast and 2nd line make the exception for chinese language correcty go to /cn/somepage


the above code gives error when the root is asked:
/it/ gives error 404
/it gives error 404
/de/ gives error 404
/de gives error 404

/xx should go to /xx/home?ln=xx
/xx/ should go to /xx/home?ln=xx

this is all on the condition that no /xx/certainpage is set, ofcourse! Thanks for any clues!

share|improve this question
up vote 1 down vote accepted

You need a rule like:

RewriteRule ^([a-z]+)/?$ /$1/home?ln=$1 [L]

This also covers the case for URLs like as well as Place this as the last rule in the chain and it will used only if nothing else matches.

share|improve this answer
Thanks very much ServerNinja! From your solution, i figured out that this would suffice too RewriteRule ^([a-z]+)/?$ /$1/home [L] when would one choose for [L] wand when for [R=301,L], which do you advise? – Sam Dec 3 '10 at 9:38

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.