How to create redirect all external links in wordpress

5

Last modified: March 22, 2014


If you are running a affiliate website and you want to cloaking and redirecting all external links in your website ? So in this tutorial we will show you How to create redirect all external links in WordPress.


create-redirect-external-links-wordpress

Example external link: http://www.example.com

Url alias to redirect to an outside site: http://tutozone.net/redirect.php?url=http://www.example.com

Now following the instructions bellow:

Step 1: Download this file: javascript.js (209 downloads) . Open it and change this line to your address

a_to_ve[i].href = "http://tutozone.net/redirect.php?url=" + a_to_vi;

To

a_to_ve[i].href = "http://yoursite.com/redirect.php?url=" + a_to_vi;

Step 2: put this code in your file “footer.php” of your theme

    //link to this js file you have downloaded above
    <script src="http://yoursite.com/link_to_this_javascript.js" type="text/javascript"></script>
    <script type="text/javascript">
    //name of the sites that you want to exclude. only the name.
    protected_links = "myspace,ebay";
    redirect_refer();
    </script>
    <!--script at the end of the body-->

Step 3 : Finally, create a file called “redirect.php” in your root directory with the code:

//get the link
$str = $_GET['url'];

if ($str == '') {
//if the variable URL link is empty. eg ".../redirect.php?url=" or ".../redirect.php" then redirects to home.
header('Location: http://yoursite.com/');
} else {
//otherwise redirects the external site.
header('Location: '.$str);
}

Done !

If you have any problem, Please use comment box bellow !

Share.

About Author

I'm a freelance with over 3 years experience working in PHP with CMS Wordpress and design website layout. In my spare time, I go fishing, lean internet marketing, scout new blogging strategies,free Xbox live gold codes and techniques, and work from wherever. View me on: Google+ | Facebook.

Leave A Reply