ULIX TxT Editor on Sourceforge.net






How to Region/Country/IP block your Website


Need to block countries or people from accessing your site? Or simply want to redirect other countries to another website? Use the code provided below!



Standard IP Block


Use this simple code to block or redirect certain ip address from accessing your website.
# IP Detection and redirection to appropriate domain/country site
# Redirect all IP address (replace the ## with the IP address # numerals) to same http://yourdomain.ca

RewriteCond %{HTT_HOST} ^##\.##\.##\.##
RewriteRule (.*) http://yourdomain.ca/$1 [R=301,L]



IP Block using Allow and Deny from!


This code is a little more complicated as it allows you to block multiple IPs from specific countries so an entire country will lose access to your website. In this example we will block all of Iran (IR)
# Iran (IR)
deny from 2.144.0.0/15 2.176.0.0/12 5.52.0.0/16 5.234.0.0/16 37.254.0.0/16 46.100.0.0/16 46.164.64.0/18 85.185.0.0/16 86.109.32.0/19 91.241.20.0/23 94.101.128.0/21 94.101.176.0/20 94.101.176.0/20 95.38.0.0/16 109.122.192.0/18 178.131.0.0/16 178.157.40.0/22 178.173.128.0/17 188.158.192.0/19 212.80.20.0/23

When using this code, the visitors from that country will see your 403 Forbidden or 404 Not Found error pages.