As most of you know I’m no domainer. I think I own a grand total of 100 domains or less. However one of our readers is and asked for an easy script to redirect their domains in a time based fashion. He mentioned that after tracking his domains he finds that sometimes redirecting the traffic to a parked page makes him more money for those times then it would redirecting it to an affiliate offer.
“I am looking for some kind of script, apps, or any kind or solution that will let me have a complete archive of all of may domain names and basically redirect each one to either my server, parking program or affiliate pages.
I know there are certain scripts out there with a control panel to organize /redirect domains but I want to take my domains one step further and have some of them redirect only on a hour, day, week, month schedule.”
You can read the comments where the conversation stemmed from here here.
The Domainer Time Based Redirect Project
For this project we have a few goals
Sounds fairly simple but it’ll be a bit complicated. That’s why I’m going to split this tutorial into 2 parts.
Let’s get going.
How to point your domains at your server using Namecheap.
Since I’m talking to domainers I imagine that most of you know how to handle DNS and how to point your domains at a server. However I’ll cover how I handle it using Namecheap. I’ve mentioned before I’m a huge fan of Namecheap as their control panel and features are fantastic. If you don’t use Namecheap and use some other registrar you’ll need to get your domains pointing to your server on your own.
First thing we’re going to need to get is the Ip address of your server where you’re running apache and we’re going to be pointing your domains at. If you don’t know this the easiest way is going to be to use a command like ping to the server if you’re used to using a domain. you’ll get back a number that has 4 parts separated by periods called an IP address. This is where we’re going to point your domains at when we login to namecheap. Let’s use oooff.com as an example. Lets say I didn’t know the IP of oooff.com there’s a few ways we could get it. One way would be just ping the address by going to start/run then typing in “ping oooff.com”. Or there’s a lot of services out there to get IP’s for example you can go here., put in the domain server domain and it’ll return a number that looks like this 220.127.116.11. This is going to be the IP address for oooff.com.
Once we have the IP address we’re going to go to namecheap and login like you normally do. Go to manage domains then click on the domains or select all the domains and hit bulk edit for the domains you want to point at this server. Next we’ll click on “All Host Records” in the left menu column. Once we’re in all host records we’re concerned with the two spots at the top. the “www” and “@”. The “www” is of course going to be where you want the http://www.oooff.com sent and the “@” is going to be where you want http://oooff.com sent. In our case we want them both sent to the same place can you guess what that is? Yep the IP address we got using the ping tool. Also we want to set “Record Type” on both to “A (Address)” as this will use the Namecheap name servers and point them at that IP. Typically this will take 5-10 minutes to update but once this time has passed when you put the domain in your browser you will probably get the default page for you server, a 404 cause your server isn’t setup to handle random domains pointing at it, really just something different then you were getting when you started.
Now that we have our domains pointing to the server we need to do some configure apache to make it do the right thing with the incoming domains. If you’ve never messed with Apache and the Apache Config file before this might be a little intimidating so I’ll make it as simple as possible. Basically the /etc/httpd/conf/httpd.conf file is what controls Apache and tells it how to handle incoming domains basically what folder/directory to send them to. So go to you server via FTP or SSH and find the httpd.conf file. It’s usually in /etc/httpd/conf/ directory if not you might need to do a little searching around to find it. Once you find it open it up and take a look through it. What we’re concerned about is the lines right towards the bottom. Called the VirtualHhost section. There’s a couple of lines in that section we’re concerned about.
# Use name-based virtual hosting.
This tells the server to use domain base Virtual Hosting which is what we want to do. Then the second lines we care about are
What this section is saying is take any incoming domain that doesn’t have a specific record and send it to that location on the server. Now the /var/www/html dir is the default for most apache servers. If yours looks like this we only need to change one thing and that’s to change the document root to somewhere else where we’re going to put our PHP file that’s going to handle all our incoming domains. If that directory doesn’t exist then I suggest making it 🙂 In our example we’ll make a directory dcontroller in /var/www/html. So our virtual host entry would look like this
And that’s it. Just save the file then restart your Apche if you’re in on the comman line via SSH just type “server httpd restart”. Or if you have a CPanel/WHM setup you can go to the interface and restart the server there. Now if you have a hard time with this just ask your hosting company as they can easily do it for you. However it’s a great thing to know how to do and understand. Every little piece helps.
Now lets test is our setup is working right. One last piece we’d need to test our setup is working it putting a index.html file in our new directory. Just make a little html file that has a “<h1>Working</h1>” in it. Save this file then go to your browser and type in the domain you setup to point to your server. If you see “Working” displayed in the browser you know you’re golden. If not you know something went wrong. Just contact your hosting support and they’ll guide you I’m sure.
That concludes part 1 of the domainer time redirection system, I’ll try and get the next part written in the next week. Let me know if you have any questions or suggestions and I’ll help if I can. I’m no *nix expert, I just know enough to get by 😀