How To Do PHP Redirect In Wordpress?

Profile picture of the author coreytucker by coreytucker Posted: 12/29/2008
Hi,

im trying to cloak a clickbank affiliate link with a PHP redirect as I heard this is one of the best ways.

I created a new directory off my root directory and then another directory in that one where I uploaded a index.php file with the code:

<?php
header("Location: myaffiliatelink");
?>

I did this but its not working. If anyone could help me with this I would be thankful
#php #redirect #wordpress

  • Profile picture of the author Jesus Perez
    Jesus Perez
    Rename the index.php file to something like myaffiliatelink.php.

    Then do a straight redirect including the php filename like so http://www.yourdomain.com/folder/myaffiliatelink.php.

    That works for me.

    Or you can get MaxBlogPress' Ninja cloaker for Wordpress. He just started a 2 day 50% discount this morning. MaxBlogPress Ninja Affiliate :: WordPress Affiliate Link Tracking Plugin
  • Profile picture of the author coreytucker
    coreytucker
    well the thing about PHP redirect is it does not hide your affiliate link after it redirects. You can still see it in the search bar right? How do you hide the link on the seach bar also?

    I would like to do this with a free method if possible. I also would like to avoid 3rd parties as I do not like the idea of having no control over this in case they go out of business etc.

    So is there some sort of PHP or html code I can use to hide the hoplink on the search url also? I cannot seem to get it to work, im using a mutiple plan hosting account where I have alot of domains on one hosting account.

    So I think all of the my sites are in the www folder and I click on the directory that is the name of the site im trying to do this one. Then I create another directory as im assuming this is the root directory and the right place to create a new directory.

    I keep getting an error when I try to visit the link that should redirect to my hoplink url.
  • Profile picture of the author Alan Petersen
    Alan Petersen
    What's the error you're getting? The way you're doing should work. Folder with a name of "recommends" or whatever. Inside that folder another folder with the product name and inside that a file with your redirect code named index.php. That means yourdomain.com/recommends/product_name should redirect. Make sure you don't have any spaces or extra characters in your code. One space will screw it up for you.

    If you want to cloak the URL you need to do framed redirect. Here is the code:

    Code:
    <HTML><HEAD>
     <META NAME="description"
     CONTENT="http://www.yoursite.com/Recommends/">
     <META NAME="keywords" CONTENT="">
     </HEAD>
     <FRAMESET border=0 rows="100%,*" frameborder="no"
     marginleft=0 margintop=0 marginright=0 marginbottom=0>
     <frame
     src="http://YourAffiliateLinkHere.com"
     scrolling=auto frameborder="no" border=0 noresize>
     <frame topmargin="0" marginwidth=0 scrolling=no marginheight=0
     frameborder="no" border=0 noresize>
     </FRAMESET>
     </HTML>
    Be careful because framedredirection violates most affiliate program TOS like ClickBank. The final destination URL should be visible on the end-users browsers window so double check the affiliate programs TOS before you try to use frame redirect.
  • Profile picture of the author coreytucker
    coreytucker
    I just did it again and created only 1 folder this time and put a index.php file in it with the same code and the error I get is :

    Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/username/public_html/mysite.com/folder1/index.php on line 3

    Parse error: syntax error, unexpected T_STRING in /home/username/public_html/mysite.com/folder1/index.php on line 3


    I do not want to use frames as you said its against CB's TOS.
  • Profile picture of the author coreytucker
    coreytucker
    I will say for the php file I simply opened up wordpad and saved the file as index.php
  • Profile picture of the author rarebiz
    rarebiz
    Greets,
    I think you heard wrong.

    This is the best way so far...

    1. Download this plugin
    ø Link Cloaking Plugin for WordPress | W-Shadow.com ø

    2. Install and Activate

    3. Relax


    Alternative plugin you can use:
    WP-Affiliate PHP Blog Affiliate Marketing Wordpress Plugin | Seo Adventures
  • Profile picture of the author coreytucker
    coreytucker
    Thanks rarebiz, but does this work well? Also how would I add a nofollow link using this plugin?

    Redirect seems like the safer way but if I cannot get it to work I will use that wordpress plugin.
  • Profile picture of the author Alan Petersen
    Alan Petersen
    You have bad data in your code. Use single ' ' instead of double " " for your URL code so it should be:

    Code:
    <?php
    header('Location: http://www.youraffiliatelink.com');
    ?>
    instead of:

    Code:
    <?php
    header("Location: http://www.youraffiliatelink.com");
    ?>
    Fix that and try again--it should work.
  • Profile picture of the author coreytucker
    coreytucker
    I get the same error when I made the fix.

    Is it ok to save a word file as .php?

    Are you sure im in the root directory since im using a mutiple hosting plan? Thanks so much for the help
  • Profile picture of the author Alan Petersen
    Alan Petersen
    Originally Posted by coreytucker View Post
    I get the same error when I made the fix.

    Is it ok to save a word file as .php?

    Are you sure im in the root directory since im using a mutiple hosting plan? Thanks so much for the help
    Use a a text editor like Notepad not Wordpad. So copy and paste the code into notepad and save it as filename.php. Notepad comes with your PC so you should have that handy.
  • Profile picture of the author coreytucker
    coreytucker
    ok oddly enough it works when I put the code into a notepad file instead of wordpad file,lol. Looks to be working!

    Let me make sure though,lol. Thanks so much for the help.
  • Profile picture of the author rarebiz
    rarebiz
    Originally Posted by coreytucker View Post
    Thanks rarebiz, but does this work well? Also how would I add a nofollow link using this plugin?

    Redirect seems like the safer way but if I cannot get it to work I will use that wordpress plugin.
    It works well and It's super safe.

    Other easy way, you can use "Redirect" menu from CPanel which generate .htaccess

    Don't use word. Sometimes word change the quote '' -> ‘’ , "" -> “” automatically. It won't work on PHP.
    Use plain text editor. Notepad or Notepad++.

    Single or double quote doesn't matter in this case.
    Using double quote you can process variables inside.

    Example:
    $world = "earth";
    echo "hello $world";
    echo 'hello $world';

    Result:
    hello earth
    hello $world
  • Profile picture of the author coreytucker
    coreytucker
    Yep it works! Thanks alot, your a life saver Im giving you a thanks!
  • Profile picture of the author coreytucker
    coreytucker
    well how do you give thanks?
  • Profile picture of the author coreytucker
    coreytucker
    also thanks rarebiz, but im just going to use the phpredirect.
  • Profile picture of the author Alan Petersen
    Alan Petersen
    Cool, glad you're all squared away! Wordpad adds weird formatting stuff we can't see so it's best to always use a text editor like Notepad when you're tweaking code since--as you've seen--it's very sensitive.
  • Profile picture of the author coreytucker
    coreytucker
    How do I give you a thanks Alan?
  • Profile picture of the author coreytucker
    coreytucker
    oh and maybe you might know the answer to this. If im doing a redirect to this one page of my site could that be bad for SEO?

    I mean I usually link to my product 2 times on each page and I have a 30 page site.

    Also do you know if I even need to add a nofollow code to this link since its linking back a internal page in my site? Thanks
  • Profile picture of the author MemberWing
    MemberWing
    The worlds best redirection plugin for wordpress is this:
    http://urbangiraffe.com/plugins/redirection/
    I use it to conceal affiliate links and "fix" renamed page - which it does automatically.
    Also supports regular expressions if you're up to this.

    Gleb
  • Profile picture of the author rarebiz
    rarebiz
    I recommend to use "nofollow" though it might not necessary.
    It should be okay because you don't user permanent redirect like this:

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

    But, it's best practice to use "nofollow" though, especially if you don't want outbound link spilling out. Every spider bot work differently.

    Your redirect method is on server side. Which means you're not linking to your internal page, but to redirect destination.

    And btw, thanks button is in the right bottom corner of each post.
    Quote, Multiquote, Quick Reply, and the one you're looking for

Related discussions