如何根据用户所在的国家/地区显示不同的主页?

How to show different homepage based on the user#39;s Country?(如何根据用户所在的国家/地区显示不同的主页?)
本文介绍了如何根据用户所在的国家/地区显示不同的主页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有两个域.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.

这篇关于如何根据用户所在的国家/地区显示不同的主页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)