Flag This Hub

Web Coding Tutorial #1: Quick And Painless PHP Redirect

By


Graphic created by Ryan Carter
See all 3 photos
Graphic created by Ryan Carter

Redirection Made Easy

Alright, so I feel like this is something that is always made WAY harder than it should be. I've been using this little trick for a few years, and, so far, it's still doing a great job. What we're going to do is set up a simple redirect script.

Here's a quick definition of what an actual redirect is (according to Wikipedia):

URL redirection, also called URL forwarding and the very similar technique domain redirection also called domain forwarding, are techniques on the World Wide Web for making a web page available under many URLs.

So, boil that down, and a redirection is basically a way to reroute web traffic that is unobtrusive, and requires no action from the user. So why do it?

Well, there are a number of reasons to employ a redirect script:

  1. To cloak affiliate links
  2. To unite misspelled alternatives to your domain
  3. To transition to a new domain
  4. To unite .com's, .net's, .org's, etc. to one domain


Graphic created by Ryan Carter
Graphic created by Ryan Carter

This Requires Your Own Hosted Domain

Why?

The reason you need your own hosted domain is because we are going to create a simple PHP web page. This page then needs to be uploaded to the desired domain. Let's say you have a product review website, and you recently finished dismantling Traffic Anarchy (not recommended). Being an affiliate for this product, you would like to get traffic to click on your affiliate link. Also, being a webmaster, you really don't want this review page to have any affiliate links on it (PPC will skyrocket).

What To Do?

Suppose your site is called Reviewosaur.com and your affiliate link is http://823b6e7ypmzi8r6a5s-zre9w7q.hop.clickbank.net/. Yep, the dreaded Clickbank link: hated by Google, despised by affiliate-marketing-customers, and a red flag to everyone else. Wouldn't it be great if you could just send people to Reviewosaur.com/traffic-anarchy-review/ or something equally pretty?

Well, lets do just that...

Step 1

First, over at Reviewosaur.com, let's just create a directory called "traffic-anarchy-review."


Step 2

Now, open up notepad and enter this text:

<?php

   header( 'Location: http://823b6e7ypmzi8r6a5s-zre9w7q.hop.clickbank.net/' ) ;

?>

If you're doing this as you're reading, you probably know that the URL after "'Location:" is my affiliate link. You would want to replace this with whichever URL you're wanting to redirect TO. Unless you want to help me with the grocery bill next month...

Now save this file as "index.php" and upload to the newly created directory: in my case it's Reviewosaur.com/traffic-anarchy-review.

Now we test it:

Don't Buy Traffic Anarchy Until You Read My Scathing Review!!

Go ahead, click the Scathing Review...

A couple of things to notice here:

  1. When you hover on the link, the innocent looking url is shown on the bottom of the browser.
  2. However, when the link is clicked, the affiliate link still shows in the address bar.

Final Remarks

Now, I'm not sure if Google has updated the Adwords PPC algorithm to take into account these shallow redirects.  If anyone knows, then by all means leave a comment.  The example I showed used an affiliate link, but the exact same technique can be used for any other link.

Just remember, the php script that we created needs to be uploaded to the url you want to bypass.  The file does not have to be named "index.php", you can actually call it "anythingyouwant.php." 

Thanks for reading, and good luck out there!

Comments

suncat 13 months ago

I guess php works better than java in case java is off on someone's computer. But what about framing a page you want to redirect to into another page with your innocent url? Or using a short url service? Not too many people even care to look at the buttom of the page when pointing at the link, much less unshort the url to see the original one.

In any case, is any of this really important or is it more just for fun kind of things? =)

ryancarter 13 months ago

Cloaking affiliate links is very important for pay per click ads, or used to be at any rate. Any site with ANY affiliate links directly in the content will be charged anywhere from 25 cents to a DOLLAR more per click!

Also, redirecting is great if you ever change domains. You'll still get traffic from all the work you put in to your old domain.

suncat 13 months ago

what do you mean by 'still get traffic from all the work you put in to your old domain' if you change domains?

How are these two related, the old and the new?

ryancarter 13 months ago

Let's say you spent the better half of last year building backlinks to the domain "suncat.com". You get a pretty good amount of traffic from this site, but you decide to go with "suncatsworld.com". You can still benefit from all your traffic and backlinks by applying this redirect.

suncat 13 months ago

I don't get your main idea. Do you keep the old domain and just start another one? Then what do you redirect and to what?

If you keep your first domain then everything on it just stays the same. So what would you do with the new links? Are they on the old or new domain?

ryancarter 13 months ago

Well, honestly, the MAIN idea of the hub is to redirect affiliate links. The other stuff is just an answer to a "what if?" scenario. Moving domains can be a headache, but this could help. Anytime you move from, say, a .org, .net, or whatever to a .com, this redirect is a great way to keep your traffic steady.

Submit a Comment
Members and Guests

Sign in or sign up and post using a hubpages account.



    Like this Hub?
    Please wait working