PHP makes redirecting users very easy. There are countless ways how you can redirect visitors to other pages. Let’s take a look at a few examples

Php Redirects Explained

Redirect to new website using header

The easiest method to redirect visitors is by using “header” wrapped in PHP tags right before the DOCTYPE tag.


Redirect after X seconds

If you want to redirect visitors after reading a redirect message or similar, you can simply append refresh:X where X is the time in seconds.


This will delay the redirect for 15 seconds. 3-5 seconds is what I would recommend if you only want to display a quick message. That would be sufficient for your visitors to scan the message and move on.

Redirect passing URL as session variable

One good way to redirect is to use a bridge PHP file called out.php or 1st.php

Insert into your bridge file e.g. out.php:

$url= $_GET['url'];  
$_SESSION['firstURL'] = $url;
header("refresh:1;url=" );  

Then in your frame.php or 2nd.php file insert:

$posturl = $_SESSION['firstURL'];  
<iframe height="1024" id="preview-frame" src="<?php echo $posturl;?>" name="preview-frame" frameborder="0" noresize="noresize"></iframe>

Redirect To URL Without Using Header

You can use a meta refresh

<META http-equiv="refresh" content="0;URL=">

Please note that HTML meta refreshes are not very user-friendly. Users can disable them in their browser. Actual PHP redirects cannot be disabled and will be enforced.

Redirect To URL Using HTACCESS Mod_Rewrite

The most trivial way to redirect any given URL is to simply use Apache’s Mod_Rewrite. You should already have a htaccess file.

Simply insert this at the top of the file:

Redirect /post-article.html

Here’s another example redirecting a page to a different domain:

Redirect /post-article/

And another for a file called creative.php

Redirect /creative.php

Cloaking Affiliate Links

Affiliate links are never pretty and should be cloaked. This is perfectly user and SEO-friendly and may even cause less damage than putting real affiliate links on your website. Google will still detect the redirect, but you are only indirectly linking to a different domain and can disallow the bridge file in your robots.txt



Redirect to /creatives/bridge.php => Redirect to actual offer

  if (isset($_COOKIE['tracking202outbound'])) {
	$tracking202outbound = $_COOKIE['tracking202outbound'];     
  } else {
	$tracking202outbound = ''.$_COOKIE['tracking202pci'];
header('location: '.$tracking202outbound);

This is an example straight from Prosper202, which is one of the leading affiliate tracking systems on the market.


Disallow: /creatives/* 

Redirect After Form Submission

1. Create your form

2. At the bottom of your form directly below the input type=”submit” insert this:

 if (!empty($_POST['value'])){

This will only redirect after a user has hit the button submit AND only if the variable “value” is not empty.

You may have to insert a few more checks to make sure all of your fields are entered properly and you may want to insert an else statement as well to display an error message. That is up to you.


There are many ways to redirect visitors and many reasons why you should know everything there is about redirects.

Please do not try to overdo it, Google is very picky and does not endorse Sneaky redirects, Gateway redirects, multiple requests on top of each other and other forms of confusing the visitor. Google is capable of detecting all malicious redirects. You can use bridge files to redirect visitors to affiliate offers without a problem, just don’t try to trick your users into something they don’t want to click on.

The most common purpose of bridge files is for external links and download pages.

Download pages often use “header” to initiate file downloads using MIME-TYPES. Without a bridge file this is not possible.

It is also a good idea to use a bridge file for offers or links you do not want to link to directly.