3

I'm trying to redirect web traffic from Argentina to a certain page from our website, and all the other traffic to a different page, using GeoIP and .htaccess.

This is an example of what I'm trying to use (in this example, I'm using only two countries, Argentina and Colombia.)

GeoIPEnable On

# Redirect Colombia
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CO$
RewriteRule ^(.*)$ http://www.mywebsites.com.ar/index2.html [L]

# Redirect Argentina
#RewriteEngine on
#RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AR [NC]
#RewriteRule ^(.*)$ http://www.mywebsite.com.ar/index.html [L]

Thing is, it doesn't work.

I also tried this:

RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^AR$

instead of declaring every single country I want to redirect, but didn't work, either.

Can anyone spot the problem?

Thanks in advance,

Ignacio

Aramis Sistek
  • 31
  • 1
  • 6
  • In your example the settings for Argentina are marked as comments. I would assume that this will not do anything... – Uwe Allner Sep 09 '15 at 11:50

2 Answers2

1

In your .htaccess, put following code This will redirect all traffic( outside of India) to https://newexample.abc.com

<IfModule mod_geoip.c>
            GeoIPEnable On
            RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^IN$
            RewriteRule ^(.*)$ https://newexample.abc.com/$1 [L]
</IfModule>
  • where i can get the country code list for `.htaccess` like should we use `^US$` or `^USA$` – Rajeev Ranjan Sharma Jan 16 '22 at 06:55
  • @RajeevRanjanSharma: You could use this country code list https://www.iban.com/country-codes or this https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 - always use the 2 letter "alpha-2" abbreviation – PeterCo Nov 24 '22 at 09:10
0

did you try to do the equal the syntax used for Colombia ?

    # Redirect Argentina
    RewriteEngine on
    RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^AR$ 
    RewriteRule ^(.*)$ http://www.mywebsite.com.ar/index.html [L]
    
I think [NC] is not necessary because GeoIP database is Uppercase (as I see on csv).

You can find more at http://dev.maxmind.com/geoip/legacy/mod_geoip2/#Examples
  • where i can get the country code list for `.htaccess` like should we use `^US$` or `^USA$` – Rajeev Ranjan Sharma Jan 16 '22 at 06:54
  • @RajeevRanjanSharma: You could use this country code list https://www.iban.com/country-codes or this https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 - always use the 2 letter "alpha-2" abbreviation – PeterCo Nov 24 '22 at 09:10