1

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

HOWEVER

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!

1

You need a rule like:

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

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

1
  • 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 clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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