Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

What I'm looking for is to direct visitors to geographically separate servers based on their choice of language.

Our URLs are structured like mydomain.com/en and mydomain.com/th (Thai). As on now everything's hosted on the same server. However, for visitors who are opting for the th language, it is preferable that we serve them from a server that is situated within Thailand. The page load speed for Thai visitors improve significantly this way.

My platform is Apache, Linux, MySQL - the regular LAMP stack. So... is it possible to configure Apache in such a way so as to redirect all traffic in the way I stated above? Keep in mind, the domain name cannot be changed, nor can we use subdomains. It HAS TO BE in that folder like format.

Thanks,
m^e

share|improve this question
    
perhaps anycasting would be of use to you. –  SpacemanSpiff Jul 5 '11 at 3:57
    
No, anycasting is of no practical use for TCP traffic. –  womble Jul 5 '11 at 3:59
    
@Spaceman, Anycast wont be able to determine the server based on the requested language, but would work for directing based on source IP (which is probably much better, though not exactly what he wants). Should post it as an answer, best option he's getting. –  Chris S Jul 5 '11 at 4:01
    
@Womble, I'm curious as to what kind of traffic you think Anycast is practically useful for? –  Chris S Jul 5 '11 at 4:03
    
@Chris: Stateless request/response UDP packets. No chance of routing topology changes causing your conversation to go to a different server mid-stream. –  womble Jul 5 '11 at 4:07

3 Answers 3

If you could redirect people to localised subdomains after the fact, this would work:

RewriteEngine on
RewriteRule ^/th(.*)$ http://th.example.com$1 [R,L]
RewriteRule ^/en(.*)$ http://en.example.com$1 [R,L]

Unfortunately, given that you're running off a single hostname that means you're limited to things in DNS (GeoIP), and can't deal with anything in the path part of the URL, so you can't make decisions based on it.

Basically, you're screwed given the constraints you've provided. Explain to those making the rules that no matter how much they stamp their feet and pout, you can't change the laws of Internet Physics. Personally, I don't see what's so ugly about http://th.example.com/...

share|improve this answer
    
To that last comment, it could be because of application design or limits of hosting (always possible) that is preventing the use of sub domains. –  TheLQ Jul 5 '11 at 5:23
    
So fix your application design or hosting. –  womble Jul 5 '11 at 14:10
1  
The problem with using language-code based subdomains here is that we're already using subdomains for other web-services, e.g. lib.xxx.yyy (Library), reg.xxx.yyy (Registration) etc. So using the en/th subdomains on top of that doesn't make sense. Otherwise, the job would have been a whole lot easier :) –  miCRoSCoPiCeaRthLinG Jul 12 '11 at 1:54
    
It still makes sense. th.lib.xxx.yyy is still a valid domain, as is lib.th.xxx.yyy. –  womble Jul 12 '11 at 5:08

This is perhaps a bit of a hit and miss approach, but consider using a geolocation aware DNS server - one suggestion is GeoIPDNS a drop-in replacement fork of TinyDNS.

The idea would be that you host an authoritative name server on your machine, and based on the IP it would automatically redirect users to one server or the other. The user's machine should cache the DNS request, so that the lookup is only made once in a while (i.e. not every page request).

You can host both the /en and /th versions on both servers, and the DNS solution will send users to the geographically correct server. Users still are able to choose which version of the site they wish to view, and the geolocation is transparent without increasing latency except for the initial DNS request (of course, you would host your DNS on both servers to provide a fall back).

share|improve this answer
1  
...and now I notice that womble already suggested GeoIP - sorry. –  cyberx86 Jul 5 '11 at 4:37

Alias the folder "/th" through a reverse proxy server to the IP address of the Thai server.

Apache itself would be the reverse proxy, by the way...

See more info here: http://httpd.apache.org/docs/2.0/mod/mod_proxy.html#proxypassreverse

This would make it so that

www.example.com/th/hi-there

is converted by apache to

thai.ip.add.ress/hi-there

And it's completely transparent to the user, no redirects or anything like that.

share|improve this answer
3  
this wouldn't improve throughput or latency though because everything is still served by the www.xxx.yyy server in the end. –  Marcel G Jul 5 '11 at 7:00
    
You're right, I didn't think about that.. hmm... –  Soviero Jul 5 '11 at 15:50
    
This solution does solve the problem for linking a folder to another server which is a problem I was looking to solve. I didn't need the geolocate aspect for speed so I'm glad I found this answer. –  XOPJ Jan 16 at 22:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.