On shared hosting servers where the Litespeed web server is used,
GeoIP module with databases of countries and ASN networks is installed and configured for operation.
You can use this module by adding rules to the .htaccess configuration file
This file should be in the root of the site, if you do not have such a file, then create it using a file manager in the control panel hosting DirectAdmin or FTP.
Examples of module use:
Example 1: block access to wp-login.php and xmlrpc.php files from certain countries.
<IfModule mod_geoip.c>RewriteEngine onRewriteCond %{ENV:GEOIP_COUNTRY_CODE}!^(GB|DK|US|IN)$RewriteRule (wp-login|xmlrpc).php$ -. [F,L]</IfModule> |
Example 2: redirects visitors based on country.
<IfModule LiteSpeed>GeoIPEnable On# One country forwardingRewriteEngine onRewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^UA$RewriteRule ^(.*)$ https://site.ua$1 [R,L] # Forward multiple countries to one addressRewriteEngine onRewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^(SK|CZ|PL)$RewriteRule ^(.*)$ https://site.com$1 [R,L]</IfModule> |
You can also use this module in PHP scripts, where the environment variable $_SERVER[‘GEOIP_COUNTRY_CODE’] is available.
but to do this you need to enable the GeoIP module in the .htaccess configuration file
<IfModule LiteSpeed> GeoIPEnable On</IfModule> |