Archive for the ‘Tutorials’ Category

Filtering Out Unproductive Trafffic

Not too long after first setting up my first TGP’s I learned that certain countries tended to be the source of exploits and attacks against my servers. Additionally since the whole idea of running a TGP is to sell subscriptions to adult content sites, it would make no sense to waste bandwidth and server resources to give surfers content who are in countries where they most likely will not be able to purchase those subscriptions. Coupled with the exploit threat, that traffic is just not worth the risk.

 

After some research I decided to take an approach using the GeoIP country code database, coupled with the mod_geoip Apache module, and rewrite the browser headers with the Apache mod_rewrite module. If you do not use Apache, or if your hosting company does not allow you to enable or install additional modules, this method will not work for you.

 

So my first step in this process was to find a company that might be able to convert this traffic, or at least pay me something for it. After trying a number of companies I now use the FRIEND FINDER NETWORK, and direct surfers to a dating site in their local language.

 

The next step was to find a way to determine which country the surfer was from, and after some investigation I settled on the GeoIP database by MaxMind. In order to install GeoIP and to have it accessible to the Apache web server so that a country determination can be done, there is three basic steps that has to be done.

  1. First you need to download the database itself and install to a location on your web server
  2. Then the Apache mod_geoip module needs to be installed
  3. As a final step the configuration file for that module must be told how to find the GeoIP data

In my case all I had to do was create a file in my conf.d directory called geoip.conf with the following entries. Don’t forget to load the module in your httpd.conf configuration file as part of the module install, and restart your Apache after install.

 

**** geoip.conf *******

<IfModule mod_geoip.c>
GeoIPEnable On
GeoIPDBFile /var/lib/GeoIP/GeoIP.dat
</IfModule>

 

Then I required a way to send the traffic to my affiliate before it consumes any of my resources, and since I was using Apache the solution was simple, the Apache ReWrite module. In my case I already had the mod_rewrite module installed, so if that is not currently installed in your Apache then that is the first step, and depending on your Apache setup there is different ways to do it, and I will not get into that part of the install here.

 

After the ReWrite module is installed, then one of the ways to instruct Apache to do certain actions is by placing a hidden file in the root of a web server directory with particular directives, and those directives will override Apache’s default setup for that directory and any subdirectory, until possibly overridden again in that subdirectory by another directives file. The name of that file is most often called .htaccess.

 

So in my case I had to instruct my virtual host, in my virtual host configuration file, to allow the .htaccess file to be processed. I accomplished this by ensuring that I had a number of flags turned on in my setup as follows. In particular notice the AllowOverride All, and the +Includes. Now this has to be done for every virtual host you plan on redirecting.

 

**** SNIP START*****

<Directory “/home/domainname_com/www”>
Options +Includes +FollowSymLinks -Indexes
AllowOverride All
Order allow,deny
Allow from all
</Directory>

**** SNIP END *****

 

Once that step was accomplished, and I reloaded the web server, then I had to start redirecting my traffic. That was accomplished by creating a .htaccess file in my web root directory. I chose to redirect traffic from China and surrounding areas, Japan, and Brazil. In this case I have separated out each section into a different directive block so that I can separate each country and send to a different dating site with their language over at FRIEND FINDER NETWORK.

 

**** SNIP START*****

## Override Default RewriteEngine setting
RewriteEngine on

 

# Redirect Chinese Traffic to Asia Friend Finder Chinese Auto Geo IP
## Redirect Chinese Traffic to Asia Friend Finder Chinese Auto Geo IP
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^CN$ [NC,OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^HK$ [NC,OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^MO$ [NC,OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^MY$ [NC,OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^SG$ [NC,OR]
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^TW$ [NC]
RewriteRule ^(.*)$ http://asiafriendfinder.com/search/g841358-pct.subhtrp?race=2&show=F&age=18-27&ip=auto〈=chinese [R,L]

 

## Redirect Japanese Traffic to Asia Friend Finder Japanese Auto Geo IP
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^JP$ [NC]
RewriteRule ^(.*)$ http://asiafriendfinder.com/search/g841358-pct.subhtrp?race=2&show=F&age=18-27&ip=auto [R,L]

 

## Redirect Brazilian Traffic to Amigos Auto Geo-IP Spanish
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^BR$ [NC]
RewriteRule ^(.*)$
http://amigos.com/go/page/cover_beta13?pid=g841358-pct.subhtrp&race=6&ip=auto〈=spanish
[R,L]

 

**** SNIP END *****

 

Detailed explanation is as follows:

 

Only once in your .htaccess file you need to turn on the Rewrite Module with the “RewriteEngine on”

 

The last match before a redirect has to end in [NC] which means ignore case. This line says to enter a condition that if the GEO-IP modules country code matches “TW” which is Taiwan, then do something with it.

RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^TW$ [NC]

 

But what if you have more than one country? Then the lines preceding this last line would end in [NC,OR].

 

So essentially this redirect is a block, and you can have as many of them as you want in the .htaccess. As you can see they contain at least one condition, and more conditions if desired, and then there is the summary instruction line that tell the web server what to do with those conditions. In this case the summary line rewrites the header and send them to the landing pages over at FRIEND FINDER NETWORK with a page that I thought would be enticing to those surfers.

 

Also I tagged on a tracking for each site, in this case the .subhtscc is the subcode for all of my URL’s in one particular .htaccess file.

 

Disclaimer: Of course I cannot be responsible for any damage to your web servers, or setup, etc., from you following these instructions, do so at your own peril. Also you should ensure that every time you change or modify the .htaccess file that you verify your site is running, since an error in the .htaccess will bring down your site.