开发者

Website redirection according to location of a user

I have two websites for my organization. One is for UK and another for India. I want to redirect Users to the particular websites based on their location, whether it is UK or India. In other words UK users to UK's website and India user开发者_如何学Gos to the Indian website keeping the URL same.

What are the possible solutions?


There are many possible solutions some of which include:

  1. You could use the GeoIP Apache Module (mod_geoip) and mod_rewrite. You could either "proxy" the request, rewrite it internally, or change the directory where the files are retrieved from.
  2. You could create snippet of code that you include in your index.php (or perhaps all of your pages) that load files from a different directory. PHP also includes functions (through PECL) that use GeoIP data. More information here.
  3. You could use $_SERVER['HTTP_ACCEPT_LANGUAGE'] as the country code is often coupled along with the language. I wouldn't recommend this method as it's very unreliable.
  4. etc.


You could analyze the HTTP header Accept-Language sent by the browser and redirect accordingly, or use GeoIP, like Francois already mentioned.

But personally I'd always recommed to let the user decide himself where he wants to go.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜