Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
821 views
in Technique[技术] by (71.8m points)

wordpress - GeoIp redirect specific country Traffic to country domain?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...