URL Redirects

How to make URL redirect pages and host them on your own website.

Make a PHP redirect

  • Using a plain text or HTML editor, create a new document and paste in the PHP redirect code.
  • Save the file as filename.php.
  • Replace example.com with destination URL.
  • Change filename with the name of your choice.
  • Upload the file to YourDomain and direct traffic to the file.

PHP Redirect Code

<?php
header( 'Location: https://example.com' ) ;
?>

Example one - filename.php

  • https://YourDomain.com/filename.php
  • https://YourDomain/directory/filename.php

Example two - index.php

The redirect file can also be named index.php if it's placed in it's own directory. With this method we only have to direct traffic to the directory not the file.

  • https://YourDomain.com/directory/
  • https://YourDomain.com/affiliate-links/name-of-product/

htaccess 301 redirect vs PHP redirect

A frequent use case for the PHP redirect is redirecting affiliate links. This makes it easy to change the affiliate link later for whatever reason.

Example

You might have thousands of eBooks downloaded all containing affiliate links. Or you might have thousands of social media posts all with affiliate links. Or you may have hundreds of social media identities all containing links in the bio.

In these cases, it makes sense to use the php redirect so the destination of all those links can be changed quickly.

However, the htaccess 301 redirect is a better choice if your redirect is a permanent move of pages on your server.

More