If you've read some of my other tutorials, you already know that your .htaccess file can do a heck of a lot more than just keep someone from hot linking your pictures. When you are hosted with some of the larger companies out there, it might be your only viable method of communicating with the server directly.
Because that's what .htaccess does. It is a file that gives exact commands to the server. Commands that tell the server how to respond in a certain situation or environment.
Now to keep this simple, we won't go into the different modules that you can utilize in .htaccess like mod rewrite, or all the other mod's out there. Because there are many. All mod stands for is 'module', an additional piece of software to be used by the server.
Now if you are on a windows server, you can stop reading this now. .htaccess is only an option if you are on a Unix, Linux, Apache type server.
Down to today's topic. Redirecting foreign traffic using htaccess.
Before I write a single detail though let me say this.
All traffic is valuable, just in different ways. Do NOT just copy and paste any of the code that follows, blindly into your htaccess file. Please research your options fully. Read several sources and find the best solution for you. Each server and it's environment is different.
Be sure to ask lots of questions before you start wildly adding commands. It could result in a costly crash, or serious bandwidth overages that would also cost you a pretty penny. Do not simply take my word for it and copy my examples without knowing what the results can be.
In a nutshell, there are a few different ways to redirect traffic using your .htaccess file.
Originally the whole concept was centered around BLOCKING a certain IP block rather than redirecting. The basic function for this was either to ALLOW or DENY a user that originates from a certain IP block. Very useful in having a secure area or folder. You can block ALL IP's except your's if you happen to have a static IP, or you could allow your general IP block that your ISP owns to have access. Still in effect cutting down your security risks substantially.
If you wanted to just block an IP, you would add something like this to your htaccess:
Code:
order deny,allow deny from 1.2.3.4 deny from 5.6.7.
In the above example, you are blocking two separate IP's. 1.2.3.4 and 5.6.7.
As I said before, you could also use wildcards to block all users from those blocks. 1.*.*.* would not only block 1.2.3.4 , but it would block every user coming from the IP block starting with the number 1. Millions of users in most cases.
So how can we use this process to redirect foreign traffic?
Instead of using a flat htaccess command like order, allow, or deny, we could use a rewrite rule or condition instead. This does require that you have mod rewrite for your server or it won't work. To test it, use one of my earlier tutorials and do a simple 'www' or no 'www' url redirect and see if your server has the capability.
Now, I don't want to go thru all the different ways you can redirect IP's or domains or certain hosts in this tutorial. It is easily done and there are a jillion tutorials out there on this topic. So for the sake of brevity, I'm going to focus on one particular method. But we do need to cover one thing. There is a big difference between a flat rule and a conditional rule.
If your syntax is wrong and you only put in the rule and not the condition, it will be a catch all, changing your site's access to all users. Syntax for your rules and conditions are VERY important.
One character in the wrong place can mean the difference between a really great new setup, or your entire site's access blocked and 500 internal errors for all your users.
Once again, proceed with caution when altering these files.
So now we want to figure out how to push all that foreign traffic to something a little more useful or profitable. We could make a list of all the foreign / undesirable IP blocks and list them out, line by line. This is how it was done for a long time.
But think of the hundreds and possibly thousands of lines of directives you would have to include in your htaccess. A giant headache to say the least. Time consuming and leaves a good chance for error along the way.
But that issue has been solved by many different IP location modules, primarily Geo mods.
In this instance, we are going to look at the Geo IP module. All Geo IP mod contains is a simplified 'country code' system that streamlines your code using it's database for reference. What I mean by this is simple. Instead of listing possibly hundreds of different IP blocks for a given country, you will only use ONE country code.
For example, if you wanted to redirect users originating from Mexico, then you would use something like this:
Code:
RewriteEngine On RewriteCond %{ENV:GEOIP_COUNTRY_CODE} ^MX$ [NC] RewriteRule ^(.*)$ http://myredirection.url [R,L]
This would send them to 'myredirection.url' . So the first thing you want to do before you start adding a single line to your htaccess, is to decide where you want to send these users.
There are many companies that will buy your unwanted traffic and pay for each user you send. However, unless you are running a million hit's a day, they are probably not going to give you much for it. Pennies.
So it's much wiser to find a good way to use the traffic yourself. One way is to find a good affiliate that caters to a specific demographic and location. So this is going to take a little research. You will not only want to find the affiliate, but if at all possible, you want to tie it into your sites general focus / topic, so that you have a better chance of converting that traffic into cash.
It may not always be possible, so just do what you should always be doing when considering a new program. Put yourself in your users shoes and try to imagine what they are looking for. What their interests might be, etc.
You're probably going to want to break down different types of foreign traffic into separate blocks, sending each block to different pages you have setup for that demographic. For example:
Using the country codes for primarily Chinese users and sending them all to a single page setup for a Chinese affiliate program. In this case, 'mydomain.com/chineseusers.html ' .
You'll want to follow this pattern throughout, unless you've decided to move it all to one place, or have sold it all to a foreign traffic buyer. You can break it down as much as you want too, sending each country to it's own page if you prefer.
If you need assistance in building a solid GEO redirect plan for your traffic, please feel free to contact me by using the contact form on my site: http://www.chuckcrawford.com/
I realize that this is a very brief overview, so once again, please do your homework before putting a lot of time into building separate pages, lining up affiliates, etc. Make sure that your host offers a Geo module in the first place, not all do.
If you have a Dedicated, VPS, UNIX / Linux / Apache server environment and have root access, you may be able to install one yourself. Make double sure you know what you're doing in this instance before you start installing modules at server level. Not all server software plays well with others and a bad mix can result in catastrophe. Do not contact me AFTER you've destroyed your build. Call me BEFORE if you're unsure. :) You are welcome to call my office and schedule a consultation, the number is (866) 75-chuck . My team can help you with not only Geo redirection, but all facets of development. We are YOUR development team. Just a phone call away. To summarize, .htaccess can do some seriously amazing things. It can change how files are used and accessed, redirect users, require user information, be used as a simple password program, rewrite url's, restrict access, and much, much more. Take the time to research it's power and you'll be very surprised at some of the tricks you can do.
Until next time,
Did you find this article useful? For more useful tips and hints, points to ponder and keep in mind, techniques, and insights pertaining to credit card, do please browse for more information at our websites. http://www.yoursgoogleincome.comhttp://www.freeearningtip.com