Drupal switch domain per continent module

Drupal is known to have very good support for multi-site installations (with both shared content and / or just shared modules, themes and core codebase). Drupal is also known to have very good i18n (internalization) and l10n (localization). So in theory a website that needs to cater different content to different continents / regions plus translate it shouldn’t be a problem right? WRONG! 🙂

Here is one of the problems encountered and of course our solution in form of “magic” custom module…

The problem: the client wanted to use geo-location to redirect users to the right domain – content specific sub-site we were using the great domain module for managing the multisite content.

Surprised as we were, we couldn’t find a module for this basic use case, (through we saw other geoip modules switching the language but not one that would switch the domain) so here is the module.

Nothing fancy in the module’s info file:

In our module we also utilize the install file:

now to the main module file, in our case we are using a free geoip api from http://freegeoip.net/ but you could replace it with any other geoip api.

we are also not going strict to continents so we added our own routing, here are the subsites we use:

  • North America
  • Europe
  • Oceania / Australia
  • South America / Brazil
  • Hong Kong
  • China / Rest of Asia

so here is the module code:

As you see were are also redirecting only in case, that person comes to the home page.

Have a better way of accomplishing it? any comments on the above code? let me know in the comments below…

, , ,

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu