How To Do PHP Redirect In Wordpress?

by 26 comments

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:

header("Location: myaffiliatelink");

I did this but its not working. If anyone could help me with this I would be thankful
#programming #php #redirect #wordpress
  • Profile picture of the author Jesus Perez
    Rename the index.php file to something like myaffiliatelink.php.

    Then do a straight redirect including the php filename like so

    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
    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 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/ on line 3

    Parse error: syntax error, unexpected T_STRING in /home/username/public_html/ on line 3

    I do not want to use frames as you said its against CB's TOS.
  • Profile picture of the author 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
    I think you heard wrong.

    This is the best way so far...

    1. Download this plugin
    ø Link Cloaking Plugin for WordPress | ø

    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 rarebiz
  • Profile picture of the author 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 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 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 coreytucker
    Yep it works! Thanks alot, your a life saver Im giving you a thanks!
  • Profile picture of the author coreytucker
    well how do you give thanks?
  • Profile picture of the author coreytucker
    also thanks rarebiz, but im just going to use the phpredirect.
  • Profile picture of the author coreytucker
    How do I give you a thanks Alan?
  • Profile picture of the author 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
    The worlds best redirection plugin for wordpress is this:
    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.

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

    header("HTTP/1.1 301 Moved Permanently");

    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
  • Profile picture of the author coreytucker
    alright thanks everyone! I gave you guys thanks. I will go ahead and use the nofollow link and see how that goes. Have a great night all
  • Profile picture of the author imnoob
    Hi, i just started a wordpress blog. It is hosted by wordpress itself. Can someone give me a step by step guide to do a php redirect? I'm new to this. Thanks in advance.
  • Profile picture of the author zoobie
    well imnoob first you need a plugin that allows to run php inside wordpress and it's called phpexec. Do a search in google and find the download link.

    After you upload to the plugin folder in your wordpress installation,
    ("wp-content/plugin" I think it's the directory) then go to your admin panel and activate it. Once you have done the step above,

    by the way why you want to do this? imnoob. the normal command is
    PHP Code:
    'Location:' ) ;
    but you can't do it normally inside your post as wordpress returns you error.
    you have to create an empty page template inside the wordpress and use the redirection code above

    hopes that help.
  • Profile picture of the author jminkler
    Here is what you all are probably missing

    When you save a file in notepad ...


    <you must select All Types here>

    If you leave it as the default the file end up being


    And you won't see it cause usually the file extensions are hidden on windows, so you have to select all types.

Next Topics on Trending Feed