How to create redirect all external links in wordpress

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: https://designssave.com/redirect.php?url=http://www.example.com

Now following the instructions bellow:

Step 1: Download this file: [Download not found] . Open it and change this line to your address

[code lang=”js”]a_to_ve[i].href = "https://designssave.com/redirect.php?url=" + a_to_vi;[/code]

To

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

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

[code lang=”js”]
//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–>

[/code]

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

[php]//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);
}
[/php]

Done !

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

Leave a Reply

Free Designsave Spinner 100% Unique & Readable!Free Spinner