After installation of Apache2 and php follow below step to achive country wise redirection.
#apt-get install libapache2-mod-geoip
Edit geoip.conf file and uncomment mentioned line.
#nano /etc/apache2/mods-available/geoip.conf
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat <-- uncomment this line with remove # from starting of line.
</IfModule>
save and exit. Once restart apache server
#/etc/init.d/apache2 restart
Now, Make one file to test.
#nano /var/www/html/example.php
Enable mod rewrite module in php
#a2enmod rewrite
Again restart the apache server.
#service apache2 restart
Edit default apache host file and add below mentioned lines before </VirtualHost> tag to redirect url country wise.
#nano /etc/apache2/sites-available/000-default.conf
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
</IfModule>
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^IN$
RewriteRule . /example.php [L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^DE$
RewriteRule . /2.php [L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule ^(.*)$ http://www.yahoo.com$1 [R,L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://www.google.com$1 [R,L]
Save and exit. Once restart apache server.
#service apache2 restart
Brief Information about the lines.
1) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^IN$
RewriteRule . /example.php [L]
Above line will redirect your default page to example.php in your root directory (html folder) If opened with INDIAN IP.
2) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^DE$
RewriteRule . /2.php [L]
Above line will redirect your default page to 2.php in your root directory (html folder) If opened with GERMANY IP.
3) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule ^(.*)$ http://www.example.co.us$1 [R,L]
Above line will redirect your default page to another URL. If opened with US IP.
4) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://www.google.com$1 [R,L]
Above line will redirect your default page to another URL. If opened with CANADA IP.
Use your desire setting to achive your goal !!
#apt-get install libapache2-mod-geoip
Edit geoip.conf file and uncomment mentioned line.
#nano /etc/apache2/mods-available/geoip.conf
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat <-- uncomment this line with remove # from starting of line.
</IfModule>
save and exit. Once restart apache server
#/etc/init.d/apache2 restart
Now, Make one file to test.
#nano /var/www/html/example.php
Enable mod rewrite module in php
#a2enmod rewrite
Again restart the apache server.
#service apache2 restart
Edit default apache host file and add below mentioned lines before </VirtualHost> tag to redirect url country wise.
#nano /etc/apache2/sites-available/000-default.conf
<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
</IfModule>
RewriteEngine on
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^IN$
RewriteRule . /example.php [L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^DE$
RewriteRule . /2.php [L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule ^(.*)$ http://www.yahoo.com$1 [R,L]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://www.google.com$1 [R,L]
Save and exit. Once restart apache server.
#service apache2 restart
Brief Information about the lines.
1) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^IN$
RewriteRule . /example.php [L]
Above line will redirect your default page to example.php in your root directory (html folder) If opened with INDIAN IP.
2) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^DE$
RewriteRule . /2.php [L]
Above line will redirect your default page to 2.php in your root directory (html folder) If opened with GERMANY IP.
3) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^US$
RewriteRule ^(.*)$ http://www.example.co.us$1 [R,L]
Above line will redirect your default page to another URL. If opened with US IP.
4) RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CA$
RewriteRule ^(.*)$ http://www.google.com$1 [R,L]
Above line will redirect your default page to another URL. If opened with CANADA IP.
Use your desire setting to achive your goal !!