Forum Moderators: mack
Redirect based on Country?
I basically have 2 sites. A .ca and a .com Site.
The .ca is canadian content, and the .com is american content.
I need users to be redirected based on IP. If they are US clients, I want them to get the .com site.
Canadian users get the .ca site.
I need this more than any other web tip in here...
PLEASE PLEASE HELP me....
Anyone who can refer me to where I can make this possible.
3D
IP's from all over the world [webmasterworld.com]
Need some help with IP/country identification [webmasterworld.com]
language based redirection [webmasterworld.com]
So simply put, there's no easy solution to this kind of problem. Some talked about users using proxies that could cause problems. One of the most accurate way seems to use DNS and resloving the host name of the visitor IP.
Hopefully somebody else will be more helpful.
mavherick
I want my site to act like Google
I have a pretty big server, and I get 500 gigs og transfer a month.
So I'mnot worried to much about any problems it may cause....
So like google were it redirects you based on the language. I'm pretty sure they use cookies right? I'd love to get some help on how they do there's weres the best place to find those answers.
:)
What about just having a US and Canadian flag on all your pages. This way the Canadians would probably go to the right section of your site and vice versa with the Americans?
Would save you a lot of troubles with people being redirected to the wrong pages just because of their IP.
I'm not sure how it is in Canada, but in Germany fx., users visting through AOL.de are indentified as being from the US.
For more on cloaking see:
Cloaking knowledge base [webmasterworld.com]
Getting the user's country from the IP address [webmasterworld.com]
Language based redirection [webmasterworld.com]
I'm in Germany, but I'm not German. I speak fluent German, but the directory is organized differently (e.g., on Google Deutschland, "Internet" is given its own category, while on Google.com it's subsumed under "Computers").
At home, the relevant cookies allow me to go to the English site when I go to www.google.com and to the German site when I go to www.google.de -- but when I'm working away from home I always end up at Google Deutschland.
Grr..r...r...
Net World Map [networldmap.com]
Geophrase [geobutton.com]
I find them to be highly accurate.
As mentioned in all the linked posts, finding out the country is very difficult - it's not like each country has it's own IP address ranges (the most you can tell from the IP is whether it's administered by the American, European or Asian agency).
You can look the country up in whois queries and filter the country of the organization that owns that IP out of the result, but that would slow your site down, I believe. At least European RIPE also offers their entire whois-database for download if you ask for it, but that's a several-hundred-MB textfile if it's decompressed, because there are so many organizations and companies owning IPs or IP ranges (and the data probably changes all the time!).
Then there's the problem of people using proxy servers, international ISPs etc.
You can get the host name (PHP: $hostname = gethostbyaddr($ip); ), from which you can extract the domain, but there are many ISPs outside the USA using .net, .com and others that don't reflect the actual country.
HTH
Your code will send me to the German version of the site even though I speak better French and my language preferences say so. 'de' *is* in my accept-language request header, but it is the one with the lowest priority. specifically, my header is 'en, fr;q=0.66, de;q=0.33'. That translates roughly as "My native language is English. If you don't have an English version, try French - I'm near-fluent. Failing that, well, I don't see an option for Creole, so I guess you can try German." My German sucks, it's just better than my Spanish or my Russian(to pick two languages I don't speak at all), and I only ever want to see a page in German if you don't have an English or French version.
Just finding the language code in the Accept-Language header isn't enough. You need to find the language code I have the highest preference for that you also support.