I’m currently working on a site that will have several sub-domains that will need a re-direct based on country origin but the server doesn’t have the mod_geoip
module allowed so I can’t use an .htaccess
redirect, like:
GeoIPEnable On
GeoIPDBFile /path/to/GeoIP.dat
# Canada
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://ca.abcd.com$1 [L]
I did some research and found that Cloudflare allows GEOlocation and I can use (code example):
$country_origin = strtolower($_SERVER['HTTP_CF_IPCOUNTRY']);
in a switch like (code is an example, hasn't been tested):
$country_origin = strtolower( $_SERVER[ "HTTP_CF_IPCOUNTRY" ] );
$clean_url = preg_replace("(^https?://)", "", get_site_url() );
if ( !empty( $country_origin ) && $country_origin != 'us' ) {
switch( $country_origin ) {
case 'et';
header( 'Location: http://' . $country_origin . '.' . $clean_url );
break;
case 'us';
header( 'Location: http://' . $country_origin . '.' . $clean_url );
break;
case 'ca';
header( 'Location: http://' . $country_origin . '.' . $clean_url );
break;
}
}
Since each subdomain would have it’s own WordPress installation as the content would be re-written and managed separately how can I check if the site is enabled in maintenance mode to stop/prevent the redirect?