Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

Our URLs are structured like and (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.


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

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

RewriteEngine on
RewriteRule ^/th(.*)$$1 [R,L]
RewriteRule ^/en(.*)$$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

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
The problem with using language-code based subdomains here is that we're already using subdomains for other web-services, e.g. (Library), (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. is still a valid domain, as is – 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
...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:

This would make it so that

is converted by apache to


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

share|improve this answer
this wouldn't improve throughput or latency though because everything is still served by the 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 '14 at 22:04

Your Answer


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.