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.








