Domanda

I need my website to have different URLs depending on the country you're accessing it from; it would work like this:

www.mypage.com ==> for users accessing from Spain - content in Spanish.
www.mypage.com/en-uk/ ==> for users accessing from UK - content in English.
www.mypage.com/en-br/ ==> for users accessing from Brazil - content in English.
www.mypage.com/en-il/ ==> for users accessing from Israel - content in English.

As of now there are only two versions of the web (Spanish and English), so for all specified countries (except Spain) the different URLs should point to exactly the same content. I'm trying to find a solution that doesn't involve having the same content copied 3 times.

I'm trying to to this with the following plugins:

WPML

Geo Redirect

But I'm struggling to make it work. I understand the problem may seem a little vague, it's just that I'm pretty lost and I'm not sure how to approach this. All suggestions would be appreciated.

È stato utile?

Soluzione

Try using a redirected URL. You can create the other (non-content) pages (www.mypage.com/en-il/) and add to the header a redirect:

<html>
<head>
....
<script>
// this will load the corresponding page
window.location.assign("http://www.mypage.com/en-uk/");
</script>
</head>
<body>
<!-- empty -->
</body>
</html>

Here is a second example where you can do the redirect from a single 404 page. Just place this code at the top level (home) of the web site in a page named 404.shtml

<html>
<head>

<script>
window.onload = function() 
{
    // Get the referring URL
    var ref = '<!--#echo var="REDIRECT_URL"-->';    

    // Break into components
    //
    comp = ref.split('/');

    if ( comp.length > 1 )
    {
        switch ( comp[ 1 ] )
        {
        case "en-br":
        case "en-il": // this will load the corresponding page
                      window.location.assign("http://www.mypage.com/en-uk/");
                      break;
        }
    }

</script>
</head>
<body>
<!-- 404 page handling here -->
</body>
</html>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top