使用GeoIP和.htaccess重定向流量

问题描述 投票:3回答:2

我正在尝试将来自阿根廷的网络流量从我们的网站重定向到某个页面,并使用GeoIP和.htaccess将所有其他流量重定向到不同的页面。

这是我尝试使用的一个例子(在这个例子中,我只使用两个国家,阿根廷和哥伦比亚。)

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]

事情是,它不起作用。

我也试过这个:

RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^AR$

而不是宣布我想要重定向的每个国家,但也没有工作。

谁能发现问题?

提前致谢,

伊格纳西奥

apache .htaccess redirect geoip
2个回答
0
投票

你是否尝试过与哥伦比亚相同的语法?

    # 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

0
投票

在你的.htaccess中,输入以下代码这会将所有流量(印度境外)重定向到https://newexample.abc.com

<IfModule mod_geoip.c>
            GeoIPEnable On
            RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^IN$
            RewriteRule ^(.*)$ https://newexample.abc.com/$1 [L]
</IfModule>
© www.soinside.com 2019 - 2024. All rights reserved.