Quick PHP Permanent Redirect

There are many different ways to redirect a visitor from one URL to another. I prefer the PHP redirect. Let’s say for example you are an affiliate for a new online store and they have given you a unique affiliate link to post on your blog to track the referrals you generate. Most of the time, this link it pretty ugly. You may want to have a URL that looks more professional or perhaps easier for someone to type or remember. You can redirect visitors from the pretty URL to the actual affiliate link instantly and still receive credit for the referral.

Like I said, there are many ways to do this, here is one…

Execute a PHP 301 Permanent Redirect

  1. Create an empty PHP file. e.g. redirect.php
  2. Copy the code below and paste it within the file.
  3. Make sure there are no spaces or other characers before the first
  4. Save. & upload.

[php]

<?
header("HTTP/1.1 301 Moved Permanently");
header("location: http://www.domain.com");
exit();
?>

[/php]

About Clifton Hatfield

He fell in love with the WordPress Publishing Platform and has been creating themes and plugins for it ever since. He is the kind of guy that can read code better than he can read a book. Often, you can find him hunched over a keyboard delivering his magic. He likes cold pizza, walking on moving sidewalks, and Indiana Jones. Clifton co-founded The Internet Lifestyle Network.
0 comments