dimanche 31 mai 2015

Amazon S3 redirect based on browser language

I've a multi language website. I want to redirect english users to /en and spanish users to /es.

Currently I'm doing it via Javascript, but I feel there is a better way.

<html>
<body>
<script type="text/javascript">
    var language = window.navigator.userLanguage || window.navigator.language;
    if (["es","en"].indexOf(language) != -1){
        window.location.replace(language);    
    }
    else{
        // other languages go to en
        window.location.replace("/en");
    }
</script>
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire