IP2location Country Blocking
Installation details...
cd /home/ec2-user mkdir ip2location chmod 2775 ip2location cd ip2location [These are the files you will have: ip2location-apache-master.zip IP2Location-C-Library-master.zip IP2LOCATION-LITE-DB1.BIN.ZIP] unzip ip2location-apache-master.zip unzip IP2Location-C-Library-master.zip unzip IP2LOCATION-LITE-DB1.BIN.ZIP [Check you have installed the following packages:] dnf -y install autoconf automake libtool httpd-devel cd IP2Location-C-Library-master vi Makefile.am [After the line AM_CPPFLAGS add the following:] ACLOCAL_AMFLAGS = -I m4 [Save and exit the editor] vi configure.ac [After the line AC_C_BIGENDIAN add the following:] AC_CONFIG_MACRO_DIR([m4]) [After the line AC_PROG_LIBTOOL add the following:] AM_PROG_CC_C_O [Save and exit the editor] [Run these commands:] mkdir m4 autoreconf -i -v --force ./configure make make install [Run these commands:] cd .. cd ip2location-apache-master apxs -i -a -L /usr/local/lib/ -I ../IP2Location-C-Library-master/libIP2Location/ -l IP2Location -c mod_ip2location.c ln -s /usr/local/lib/libIP2Location.so.1 /usr/lib/libIP2Location.so.1 [Then add these lines to the end of your /etc/httpd/conf/httpd.conf file:] <IfModule mod_ip2location.c> IP2LocationEnable On IP2LocationDetectProxy On IP2LocationSetmode ALL IP2LocationDBFile /home/ec2-user/ip2location/IP2LOCATION-LITE-DB1.BIN </IfModule> [You will notice this new line: LoadModule IP2Location_module /usr/lib64/httpd/modules/mod_ip2location.so is now in httpd.conf] [Fix file permissions:] cd /home/ec2-user/ip2location find . -type d -exec sudo chmod 2775 {} \; find . -type f -exec sudo chmod 0664 {} \; chmod 777 /home/ec2-user/ip2location/IP2LOCATION-LITE-DB1.BIN cd /home/ec2-user chown apache ip2location chgrp ec2-user ip2location [Restart httpd:] systemctl restart httpd [ Use the IBM 2 letter country codes to select your countries, and add lines like these near the top of your .htaccess file: https://www.ibm.com/docs/en/iis/9.1?topic=sets-iso-territory-codes I place the lines below my https redirect lines: (use your own domain name) RewriteEngine on RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://mydomain.au/$1 [R,L] ] vi /var/www/html/.htaccess RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^RU$ RewriteRule ^(.*)$ https://google.com.au [L] RewriteCond %{ENV:IP2LOCATION_COUNTRY_SHORT} ^CN$ RewriteRule ^(.*)$ https://google.com.au [L]