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

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