OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

I want to use .htaccess to block a country and if any other country redirect the visitor to another URL

  • Thread starter Thread starter Josh Medici
  • Start date Start date
J

Josh Medici

Guest
I have this code to prevent people from Mexico from accessing my domain name, but I wonder if I can add another line where I redirect them to another URL (A landing page on an email marketing page). IS that possible? I appreciate any and all help and details you can provide.

In summary. I want to prevent people from Mexico from accesing the main domain (maindomain.com), but if they are elsewhere, I want to redirect them to another URL (externaldomain.com).

Here's the code on my .htaccess (I removed some of the country IP listing for extension)

Code:
# -------------------------------------------------------
# Free IP2Location Firewall List by Country
# Source: https://www.ip2location.com/free/visitor-blocker
# Last Generated: 04 Jun 2024 00:54:33 GMT



deny from 217.8.116.0/24
deny from 217.76.242.0/23
deny from 223.27.114.0/24
deny from 223.119.251.0/24

order allow,deny
allow from all

I just edited the htaccess file to block the country, I wonder if it's possible to redirect them. I am hosting the domain in cPanel on a VPS. The reason we need to block the domain is because we run email campaigns in the US, and the offers are excluvise of the US, but the service we use (ActiveCampaign) does not offer geo-blocking, and we need the data analytics our mailing campaigns produce in the custom domain they provide. But we have a main domain that we want to use. Just not have it accesible from Mexico.
<p>I have this code to prevent people from Mexico from accessing my domain name, but I wonder if I can add another line where I redirect them to another URL (A landing page on an email marketing page).
IS that possible? I appreciate any and all help and details you can provide.</p>
<p>In summary. I want to prevent people from Mexico from accesing the main domain (maindomain.com), but if they are elsewhere, I want to redirect them to another URL (externaldomain.com).</p>
<p>Here's the code on my .htaccess (I removed some of the country IP listing for extension)</p>
<pre><code># -------------------------------------------------------
# Free IP2Location Firewall List by Country
# Source: https://www.ip2location.com/free/visitor-blocker
# Last Generated: 04 Jun 2024 00:54:33 GMT



deny from 217.8.116.0/24
deny from 217.76.242.0/23
deny from 223.27.114.0/24
deny from 223.119.251.0/24

order allow,deny
allow from all
</code></pre>
<p>I just edited the htaccess file to block the country, I wonder if it's possible to redirect them. I am hosting the domain in cPanel on a VPS. The reason we need to block the domain is because we run email campaigns in the US, and the offers are excluvise of the US, but the service we use (ActiveCampaign) does not offer geo-blocking, and we need the data analytics our mailing campaigns produce in the custom domain they provide. But we have a main domain that we want to use. Just not have it accesible from Mexico.</p>
Continue reading...
 

Latest posts

Top