Forum

Questions and discussions

Browser language redirection

Script's setup and configuration

Browser language redirection

Postby serge » Wed Jun 16, 2010 8:33 am

I'd like to redirect my visitors depending on their browser language.

I assume the URLs to use are:
members/language.php?lang=English
members/language.php?lang=French

I created an index.html file containing this javascript:
Code: Select all
<script>
var langcodes=new Array("en", "fr", "default")
var langredirects=new Array("members/language.php?lang=English", "members/language.php?lang=French", "members/language.php?lang=English")
var languageinfo=navigator.language? navigator.language : navigator.userLanguage
var gotodefault=1

function redirectpage(dest){
if (window.location.replace)
window.location.replace(dest)
else
window.location=dest
}

for (i=0;i<langcodes.length-1;i++){
if (languageinfo.substr(0,2)==langcodes[i]){
redirectpage(langredirects[i])
gotodefault=0
break
}
}

if (gotodefault)
redirectpage(langredirects[langcodes.length-1])
</script>

But it seems to work only when the landing URL is already chached by the browser. Actually it does not work.
Can anyone advise on an easy and seo-friendly way to redirect?

Thanks.
serge
 
Posts: 80
Joined: Wed May 05, 2010 9:10 pm

Return to Configuration

Who is online

Users browsing this forum: No registered users and 5 guests

cron
  Photo Store Script

Professional php photo stock script and WordPress plug-in for photographers and video producers.

  Support
  CMSaccount Inc.