How To Do PHP Redirect In Wordpress?

26 replies
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
    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
    Signature

    {{ DiscussionBoard.errors[368443].message }}
  • 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.
    {{ DiscussionBoard.errors[368534].message }}
    • Profile picture of the author 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.
      Signature
      {{ DiscussionBoard.errors[368570].message }}
  • 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/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.
    {{ DiscussionBoard.errors[368615].message }}
  • 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
    {{ DiscussionBoard.errors[368617].message }}
  • Profile picture of the author 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
    {{ DiscussionBoard.errors[368623].message }}
  • Profile picture of the author rarebiz
    [DELETED]
    {{ DiscussionBoard.errors[368626].message }}
    • Profile picture of the author 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.
      Signature
      {{ DiscussionBoard.errors[368662].message }}
  • 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.
    {{ DiscussionBoard.errors[368651].message }}
    • Profile picture of the author 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
      {{ DiscussionBoard.errors[368744].message }}
  • 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
    {{ DiscussionBoard.errors[368685].message }}
    • Profile picture of the author 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.
      Signature
      {{ DiscussionBoard.errors[368707].message }}
  • 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.
    {{ DiscussionBoard.errors[368714].message }}
  • Profile picture of the author coreytucker
    Yep it works! Thanks alot, your a life saver Im giving you a thanks!
    {{ DiscussionBoard.errors[368751].message }}
  • Profile picture of the author coreytucker
    well how do you give thanks?
    {{ DiscussionBoard.errors[368755].message }}
  • Profile picture of the author coreytucker
    also thanks rarebiz, but im just going to use the phpredirect.
    {{ DiscussionBoard.errors[368756].message }}
  • Profile picture of the author coreytucker
    How do I give you a thanks Alan?
    {{ DiscussionBoard.errors[368785].message }}
  • 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
    {{ DiscussionBoard.errors[368791].message }}
  • Profile picture of the author 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
    {{ DiscussionBoard.errors[368827].message }}
  • 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:

    <?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
    {{ DiscussionBoard.errors[368828].message }}
  • 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
    {{ DiscussionBoard.errors[368845].message }}
  • 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.
    {{ DiscussionBoard.errors[398411].message }}
  • 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:
    <?php
    header
    'Location: http://www.yoursite.com/new_page.html' ) ;
    ?>
    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.
    {{ DiscussionBoard.errors[398521].message }}
    • Profile picture of the author imnoob
      Hi Zoobie, thanks for the reply. Is there other ways I can do php redirect without installing anything?
      {{ DiscussionBoard.errors[400083].message }}
      • Profile picture of the author JTull
        O wow!
        I see this is a bit older thread, however I found another option that worked for me..............

        After copy/pasting the php code into notepad and using filezilla to upload to my "recommends" folder, it would just not work....

        Finally I was able to look in my /wp-content/ folder in filezilla and copied the php code directly into the index.php file......then I used somebody above's suggestion of renaming the "index.php" to "product.php"

        This worked & the code was exactly the same..!

        So while making my own notepad file did NOT work....copying and pasting the code into the index.php and then renaming & moving that file to the "recommends" folder DID work.

        Hope this helps anybody else having the same issue. !!
        {{ DiscussionBoard.errors[3461648].message }}
  • Profile picture of the author jminkler
    Here is what you all are probably missing

    When you save a file in notepad ...

    Filename:
    myphpfile.php

    Type:
    <you must select All Types here>

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

    myphpfile.php.txt

    And you won't see it cause usually the file extensions are hidden on windows, so you have to select all types.
    {{ DiscussionBoard.errors[3463275].message }}

Trending Topics