我做了一个网站,它的一些子域名;根据国家的IP地址,该用户将被自动重定向到相应的子域。
I made a site it with some subdomains; according to the country's IP address the user is supposed to be automatically redirected to corresponding subdomain.
示例:
主要网站是 abcd.com
ind.abcd.com
Suppose some one from India typed this url abcd.com,
then the page redirects to ind.abcd.com
确认你有 mod_geoip 模块(< STRONG> GeoIP的扩展)安装到服务器上。
Check that you have the mod_geoip module (GeoIP Extension) installed on your server.
然后,调整你的的.htaccess
相应文件:
Then, tweak your .htaccess
file accordingly :
GeoIPEnable On
GeoIPDBFile /path/to/GeoIP.dat
# Start Redirecting countries
# Canada
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://ca.abcd.com$1 [L]
# India
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^IN$
RewriteRule ^(.*)$ http://in.abcd.com$1 [L]
# etc etc etc...
和这里的官方文档。