THE IT IDEAS

  • Home

Thursday, 11 December 2014

Installation and configuration of GeoIP module in php

 THE IT IDEAS     15:13     geoip, php   

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 !!
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

Like Us !!!

Recent Posts

Blog Archive

  • ►  2016 (1)
    • ►  April (1)
  • ►  2015 (12)
    • ►  August (1)
    • ►  May (2)
    • ►  April (8)
    • ►  March (1)
  • ▼  2014 (23)
    • ▼  December (8)
      • How to resolve mcrypt extension missing error.
      • How to upload EC2 Data to S3 Bucket with s3cmd
      • How to move github local folder to another location.
      • Basic GitHub Commands
      • Installation and configuration of GeoIP module in php
      • Install MongoDB php driver in XAMPP/LAMPP
      • How to redirect HTTP to HTTPS
      • How to Create VirtualHost in Apache 2.4
    • ►  November (12)
    • ►  April (2)
    • ►  March (1)
  • ►  2013 (7)
    • ►  December (1)
    • ►  April (1)
    • ►  March (1)
    • ►  February (1)
    • ►  January (3)
  • ►  2012 (15)
    • ►  December (6)
    • ►  November (9)

Categories

apache2 EC2 error mysql php ubuntu aws aws rds browser github installation linux mount s3 AWS Bucket CentOS Computer DocumentRoot change How to Benchmarking Webserver IP LAMP Restart Computer SCP command SQL SERVER XRDP administrator amazon rds backup basic commands chat command line disable download drupal ec2.chroot environment external storage device fstab functions geoip gmail google home page iis instance internet java mod rewrite mongodb multiple login network password one password php5 php5-fpm php7 private browsing python repair filesystem repo reset password rhel sa password same computer script sftp share skype ssh tomcat ubuntu 16.04 ubuntu16 visudo windows 8 youtube
JobsMagBlogJobsMag.InThingsGuide

Popular Posts

  • Install MongoDB php driver in XAMPP/LAMPP
    To install the php driver for MongoDB Prerequisite :: #sudo apt-get install autoconf #export PHP_AUTOCONF=/usr/bin/autoconf #sudo apt...
  • How to Install PHP 7.0, Apache 2.4.18, & MySQL 5.7 on Ubuntu 16.04 LTS
    Update your repo list with below command $ sudo apt-get update -- > Install Apache 2.4.18 $ sudo apt-get install apac...
  • Share Internet from one PC to another PC
    Open Network Connections by clicking the Start button , clicking Control Panel , clicking Network and Internet , clicking Network and S...

Copyright © THE IT IDEAS | Powered by Blogger