1

My website has two languages: French and English. The solution I chose is working but is causing me trouble. I use session in order to keep a "clean" url which is the same in English and in France.

My solution:

To choose the language, I locate the user using IP, and if it is not in France, i set

 $_SESSION['language'] = "ENG"

Otherwise,

 $_SESSION['language'] = "FRA"

Then I includes my file words.php which contains all the text like this:

if( $_SESSION['language'] == "ENG")
{
   $word1 = "hello"
   $word2 = ....
}
else
{
   $word1 = "bonjour"
   $word2 = ....
}

Finally on my website, I have several echo $word1;.

To change language, I have a two links (one for each language) to a webpage language.php with a get parameter that just change the session variable and redirect to the webpage:

if($_GET['l']=="1")
{
    $_SESSION['language'] = "FRA";

    header('Location: ' . htmlspecialchars($_SERVER['HTTP_REFERER']));
}
elseif($_GET['l']=="2")
{
    $_SESSION['language'] = "ENG";
    header('Location: ' . htmlspecialchars($_SERVER['HTTP_REFERER']));
}

My problem: My main problem is that Google is indexing my website only in English ( guess because the IP of crawler is not in France?). In google.fr and google.com, my website is in English. What can I do to have the website indexed in both languages?

4

1 回答 1

0

您必须为语言使用其他文件夹。您可以将 example.com/fr 用于法语内容,将 example.com/en 用于英语内容。

你可以看出这个网站对于谷歌爬虫机器人来说是多语言和多区域的。根据您的目的编辑此 html 代码。

<link rel=”alternate” href=”http://example.com/en-gb” hreflang=”en-gb” />
<link rel=”alternate” href=”http://example.com/en-us” hreflang=”en-us” />
<link rel=”alternate” href=”http://example.com/en-au” hreflang=”en-au” />
<link rel=”alternate” href=”http://example.com/” hreflang=”x-default” />
于 2014-02-13T11:11:28.397 回答