GeoIp redirect specific country Traffic to country domain?

拈花ヽ惹草 提交于 2019-12-18 07:22:49

问题


I want to redirect US country traffic to my country domain from mydomain.com. My website is in Wordpress and i would prefer .htaccess. i have applied the below code but it redirecting all IP addresses to mydomain.us. Will any body help?

GeoIPEnable On
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^(US)$ 
RewriteRule ^(.*)$ http://mydomain.us [R,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

My Domains mydomains.com and mydomains.us has same structure like categories and post etc. i want to redirect mydomain.com traffic from US IPs to mydomain.us (but whole domain)

Thanks for answers by https://stackoverflow.com/users/2862485/amith https://stackoverflow.com/users/2184393/cafe-coder


回答1:


You should really check out the docs

In your case, try the following rewrite rule:

GeoIPEnable On
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$ 
RewriteRule ^(.*)$ http://mydomain.us/$1 [R,L]



回答2:


Your rewrite rules direct non-US IP's to http://mydomain.us.

If you want to redirect US IP's to http://mydomain.com try this:

GeoIPEnable On
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$ 
RewriteRule ^(.*)$ http://mydomain.com [R,L]

Or, if what you want is to redirect US IP users to http://mydomain.us, try this:

GeoIPEnable On
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$ 
RewriteRule ^(.*)$ http://mydomain.us [R,L]

It's always good to check the mod_rewrite docs



来源:https://stackoverflow.com/questions/19648241/geoip-redirect-specific-country-traffic-to-country-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!