Can I use geoip to target my site to customers of a specific country?

We have support for the geoip Apache module. This will make country information available to your server. Contact support to enable this feature.

If this is enabled, use code like:

$country_code = $_SERVER['GEOIP_COUNTRY_CODE'];

to get the country code for the ip address of the visitor.

A second solution is to use a .htaccess rule like:

<IfModule mod_rewrite.c>
  RewriteEngine on

  <IfModule mod_geoip.c>
    RewriteCond %{HTTP_HOST} ^example.com$ [nocase]
    RewriteRule ^ http%{ENV:protossl}://%{ENV:GEOIP_COUNTRY_CODE}.example.com%{REQUEST_URI} [last,redirect=permanent]
  </IfModule>
</IfModule>