問題描述
我有兩個域.rajasekar.com 和 rajasekar.in.我需要做的是,
I had two domains. rajasekar.com and rajasekar.in. What I need to do is that,
當來自印度的用戶在地址欄中輸入網址為 www.rajasekar.com 時,它應該打開 www.rajasekar.in
when a user from India types the url in the address bar as www.rajasekar.com then it should open www.rajasekar.in
當其他國家的用戶在地址欄中輸入網址為 www.rajasekar.com 時,它應該打開 www.rajasekar.com
When user from other country types the url in the address bar as www.rajasekar.com it should open www.rajasekar.com
我認為這是在 GOOGLE 中實現的.請幫助我實現這一目標
I think this is what implemented in GOOGLE. Please help me in achieving this
推薦答案
你可以嘗試根據用戶的遠程地址猜測國家.
You can try to guess the country based on the remote address of the user.
以下是一個可行的解決方案,但您必須使用重定向邏輯:
The following is a working solution, you'll have to work the redirection logic though:
$remoteAddr = $_SERVER['REMOTE_ADDR'];
$lookupUrl = sprintf('http://api.hostip.info/country.php?ip=%s', $remoteAddr);
$country = trim(file_get_contents($lookupUrl));
if ('IN' === $country)
{
$newUrl = 'http://www.rajasekar.in/';
header(sprintf('Location: %s', $newUrl));
printf('<a href="%s">Moved.</a>', $newUrl);
exit();
}
不過,請注意來自印度的搜索引擎機器人也能夠抓取 .com 內容.
Take care that search engine robots from India are able to crawl the .com content as well however.
這篇關于如何根據用戶所在的國家/地區顯示不同的主頁?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!