So let’s say I have a customer that only sells to the US. I want to redirect all of the non US visitors to a page that tells them the website is not available in their country.
I’ve always used “GeoIPEnable On” & “RewriteEngine On” in my .htaccess
For a mysterious, unknown reason, siteground doesn’t allow this. Instead we have to use a php alternative that they quite badly explain on this page
That page doesn’t explain the redirect, it explains how to display the country of the visitor.
So normally, if you want to redirect with php, you can use
header (‘location:http://non-us.hiboomedia.com’)
So we should be able to use:
if ($country == ‘US’) { header (‘location:http://non-us.hiboomedia.com’) }
Not with siteground though. they’re blocking that too…
So here’s the solution:
echo ‘<META HTTP-EQUIV=”Refresh” Content=”0; URL=http://us.hiboomedia.com”>’
Full solution: place this at the very beginning of you index.php, in front of the <html> tag
<?php $website_root_path=’/your/path/public_html/’;require($website_root_path . ‘geoip.inc’); $ip=$_SERVER[‘REMOTE_ADDR’];$gi=geoip_open($website_root_path . ‘GeoIP.dat’, GEOIP_STANDARD);
$country = geoip_country_code_by_addr($gi, $ip); if ($country == ‘US’) { } else { echo ‘<META HTTP-EQUIV=”Refresh” Content=”0; URL=http://non-us.hiboomedia.com”>’; exit; } ?>
Hope this helps.











