Create a gist now

Instantly share code, notes, and snippets.

@jdevalk /.htaccess
Last active May 21, 2018

What would you like to do?
These three files together form an affiliate link redirect script.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteRule (.*) ./index.php?id=$1 [L]
</IfModule>
<?php
$id = isset( $_GET['id'] ) ? rtrim( trim( $_GET['id'] ), '/' ) : 'default';
$f = fopen( 'redirects.txt', 'r' );
$urls = array();
// The file didn't open correctly.
if ( !$f ) {
echo 'Make sure you create your redirects.txt file and that it\'s readable by the redirect script.';
die;
}
// Read the input file and parse it into an array
while( $data = fgetcsv( $f ) ) {
if ( !isset( $data[0] ) || !isset( $data[1] ) )
continue;
$key = trim( $data[0] );
$val = trim( $data[1] );
$urls[ $key ] = $val;
}
// Check if the given ID is set, if it is, set the URL to that, if not, default
$url = ( isset( $urls[ $id ] ) ) ? $urls[ $id ] : ( isset( $urls[ 'default' ] ) ? $urls[ 'default' ] : false );
if ( $url ) {
header( "X-Robots-Tag: noindex, nofollow", true );
header( "Location: " . $url, 302 );
die;
} else {
echo '<p>Make sure yor redirects.txt file contains a default value, syntax:</p>
<pre>default,http://example.com</pre>
<p>Where you should replace example.com with your domain.</p>';
}
default,http://example.com
yoast,http://yoast.com
test,http://yoast.com/?p=2
@jdevalk

This comment has been minimized.

Show comment Hide comment
@jdevalk

jdevalk May 21, 2013

If you want to make this work with NGINX, use this gist.

Owner

jdevalk commented May 21, 2013

If you want to make this work with NGINX, use this gist.

@ramondelafuente

This comment has been minimized.

Show comment Hide comment
@ramondelafuente

ramondelafuente May 21, 2013

This script will always set the value of $url to:
$urls['id'] OR
$urls[default'] OR
an empty string

and therefore match the isset() at the end.
Without a default value you'll redirect to an empty string for missing id's.

This script will always set the value of $url to:
$urls['id'] OR
$urls[default'] OR
an empty string

and therefore match the isset() at the end.
Without a default value you'll redirect to an empty string for missing id's.

@CodeAngry

This comment has been minimized.

Show comment Hide comment
@CodeAngry

CodeAngry May 21, 2013

@future500 is right.
Missing IDs should be 301'ed to homepage to keep the link (leak) juice :)

@future500 is right.
Missing IDs should be 301'ed to homepage to keep the link (leak) juice :)

@jdevalk

This comment has been minimized.

Show comment Hide comment
@jdevalk

jdevalk May 22, 2013

Replaced the isset with an !empty, the default would take care of redirecting to the homepage so people should make sure that's set.

Owner

jdevalk commented May 22, 2013

Replaced the isset with an !empty, the default would take care of redirecting to the homepage so people should make sure that's set.

@jdevalk

This comment has been minimized.

Show comment Hide comment
@jdevalk

jdevalk May 22, 2013

Added a warning message for when default is not set :)

Owner

jdevalk commented May 22, 2013

Added a warning message for when default is not set :)

@jdevalk

This comment has been minimized.

Show comment Hide comment
@jdevalk

jdevalk May 22, 2013

Added some input checking and made slightly easier to read by defaulting the "default" value to false. Also now allows for /out/example/ (note the trailing slash).

Owner

jdevalk commented May 22, 2013

Added some input checking and made slightly easier to read by defaulting the "default" value to false. Also now allows for /out/example/ (note the trailing slash).

@jpinches

This comment has been minimized.

Show comment Hide comment
@jpinches

jpinches May 30, 2013

Does this CSV file allow for blank spaces and/or mixed case letters? I would assume so if this is using rewrite.

Does this CSV file allow for blank spaces and/or mixed case letters? I would assume so if this is using rewrite.

@christiandietrich

This comment has been minimized.

Show comment Hide comment
@christiandietrich

christiandietrich Jun 6, 2013

hey joost, thanks for that. Is there also a script for lighty available?

hey joost, thanks for that. Is there also a script for lighty available?

@mxlje

This comment has been minimized.

Show comment Hide comment
@mxlje

mxlje Jun 28, 2013

@christiandietrich Since there are no htaccess files on Lighttpd, you need to put the rewrite rules directly into the server config.

Add this somewhere to /etc/lighttpd/lighttpd.conf

url.rewrite-once = (
    "^/out/(.*)"  => "/_outbound/?id=$1"
)

I put the actual redirect code in /_outbound because I like to keep things seperate.

Also: add url.access-deny = ("redirects.txt") to the config to prevent access to the file.

mxlje commented Jun 28, 2013

@christiandietrich Since there are no htaccess files on Lighttpd, you need to put the rewrite rules directly into the server config.

Add this somewhere to /etc/lighttpd/lighttpd.conf

url.rewrite-once = (
    "^/out/(.*)"  => "/_outbound/?id=$1"
)

I put the actual redirect code in /_outbound because I like to keep things seperate.

Also: add url.access-deny = ("redirects.txt") to the config to prevent access to the file.

@ponda199

This comment has been minimized.

Show comment Hide comment
@ponda199

ponda199 Aug 14, 2013

Didn't work for me :-(

Goes always the the "default" url.

Didn't work for me :-(

Goes always the the "default" url.

@psteinweber

This comment has been minimized.

Show comment Hide comment
@psteinweber

psteinweber Aug 16, 2013

Unfortunately the script doesn't work when there is a ? in the URL which you enter in redirects.txt. That's for example the case for amazon search results.
Anyone has an idea how to fix this? Probably somewhere in the index.php, but my php is a bit rusty...

edit: Ok, the answer was actually quite simple: replacing the ? with %3F did the job. I'll leave it here in case anyone else is trying to solve it...

Unfortunately the script doesn't work when there is a ? in the URL which you enter in redirects.txt. That's for example the case for amazon search results.
Anyone has an idea how to fix this? Probably somewhere in the index.php, but my php is a bit rusty...

edit: Ok, the answer was actually quite simple: replacing the ? with %3F did the job. I'll leave it here in case anyone else is trying to solve it...

@alanreeves001

This comment has been minimized.

Show comment Hide comment
@alanreeves001

alanreeves001 Aug 19, 2013

I must be doing something wrong because I can't get this to work right. It seems to work when I link using /out/{keyword} but not when I do /out/?id={keyword}. I've tried the following:

Putting all of the code from the .htaccess in a block in my .htaccess
(works on /out/{keyword} but not the other way)

Putting just the 4th line (the last rewrite rule) in the same spot in my .htaccess
(works on /out/{keyword} but not the other way)

Tried variations of the (.*) part

When I hard code a 301 redirect from /out/{keyword} to /out/index.php?id={keyword} and remove the RewriteRule (.*) ./index.php?id=$1 [L] line, it works fine (but that almost defeats the purpose of doing all of this)

I'm stuck. Any ideas?

I must be doing something wrong because I can't get this to work right. It seems to work when I link using /out/{keyword} but not when I do /out/?id={keyword}. I've tried the following:

Putting all of the code from the .htaccess in a block in my .htaccess
(works on /out/{keyword} but not the other way)

Putting just the 4th line (the last rewrite rule) in the same spot in my .htaccess
(works on /out/{keyword} but not the other way)

Tried variations of the (.*) part

When I hard code a 301 redirect from /out/{keyword} to /out/index.php?id={keyword} and remove the RewriteRule (.*) ./index.php?id=$1 [L] line, it works fine (but that almost defeats the purpose of doing all of this)

I'm stuck. Any ideas?

@ghost

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Aug 20, 2013

@ponda199,

Make sure the /out/ directory, and the files w/in it, have the same owner:group as your WP directory.

ghost commented Aug 20, 2013

@ponda199,

Make sure the /out/ directory, and the files w/in it, have the same owner:group as your WP directory.

@ghost

This comment has been minimized.

Show comment Hide comment
@ghost

ghost Aug 20, 2013

It seems to work when I link using /out/{keyword}

@alanreeves001:

Isn't that exactly how it's supposed to work – or am I missing something?

ghost commented Aug 20, 2013

It seems to work when I link using /out/{keyword}

@alanreeves001:

Isn't that exactly how it's supposed to work – or am I missing something?

@alanreeves001

This comment has been minimized.

Show comment Hide comment
@alanreeves001

alanreeves001 Aug 21, 2013

@pcatty,

I wasn't sure if accessing the link both ways (using the direct /out/{keyword} and /out/?id={keyword}) would work at the same time. Must have misunderstood. Works fine with the direct link

@pcatty,

I wasn't sure if accessing the link both ways (using the direct /out/{keyword} and /out/?id={keyword}) would work at the same time. Must have misunderstood. Works fine with the direct link

@Parney

This comment has been minimized.

Show comment Hide comment
@Parney

Parney Oct 14, 2013

Hi. What code do I need to add to open the redirected links in a new window? Thanks.

Parney commented Oct 14, 2013

Hi. What code do I need to add to open the redirected links in a new window? Thanks.

@raitulja

This comment has been minimized.

Show comment Hide comment
@raitulja

raitulja Oct 21, 2013

Hi,
Thank you for great script. This is working well on one of my servers. However I had problems to get it to work with my new host. Finally got it working by adding "RewriteBase /myfolder" to .htaccess file. I'm not a coder, so I'd be happy if anyone can suggest the reasons, why I had to do this?

Hi,
Thank you for great script. This is working well on one of my servers. However I had problems to get it to work with my new host. Finally got it working by adding "RewriteBase /myfolder" to .htaccess file. I'm not a coder, so I'd be happy if anyone can suggest the reasons, why I had to do this?

@SEOMike

This comment has been minimized.

Show comment Hide comment
@SEOMike

SEOMike Nov 15, 2013

Would anyone by so kind and help me make this script work in WordPress?

SEOMike commented Nov 15, 2013

Would anyone by so kind and help me make this script work in WordPress?

@chrisfdc

This comment has been minimized.

Show comment Hide comment
@chrisfdc

chrisfdc Nov 18, 2013

I'm also trying to get this to work on WordPress. If my current .htaccess file looks like this:

AddHandler application/x-httpd-php5s .php

RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]

What should it look like after adding the necessary parts of the Joost .htaccess code?
Thanks!

I'm also trying to get this to work on WordPress. If my current .htaccess file looks like this:

AddHandler application/x-httpd-php5s .php

RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]

What should it look like after adding the necessary parts of the Joost .htaccess code?
Thanks!

@yakusa47

This comment has been minimized.

Show comment Hide comment
@yakusa47

yakusa47 Dec 31, 2013

Hi Joost,

I try this script with wordpress.

I have a folder "goto" with 3 files: .htaccess, index.php and redirects.txt.

In redirects.txt, I have 3 lines :
default,http://demo1.sifastore.co
sifastore,http://demo1.sifastore.co
Ping-O-Matic,http://pingomatic.com

Live URL:
http://demo1.sifastore.co/useful-blogging-tools/

Content:
Ping-O-Matic – Pinging search engines so you don’t have to.
"Ping-O-Matic" link to "http://demo1.sifastore.co/goto/Ping-O-Matic"

But the output is 404 with url address: http://demo1.sifastore.co/s/demo1.sifastore.co/www/goto/?id=Ping-O-Matic

How do I resolve the problem?

Thanks for your help.

Hi Joost,

I try this script with wordpress.

I have a folder "goto" with 3 files: .htaccess, index.php and redirects.txt.

In redirects.txt, I have 3 lines :
default,http://demo1.sifastore.co
sifastore,http://demo1.sifastore.co
Ping-O-Matic,http://pingomatic.com

Live URL:
http://demo1.sifastore.co/useful-blogging-tools/

Content:
Ping-O-Matic – Pinging search engines so you don’t have to.
"Ping-O-Matic" link to "http://demo1.sifastore.co/goto/Ping-O-Matic"

But the output is 404 with url address: http://demo1.sifastore.co/s/demo1.sifastore.co/www/goto/?id=Ping-O-Matic

How do I resolve the problem?

Thanks for your help.

@qim

This comment has been minimized.

Show comment Hide comment
@qim

qim Feb 13, 2014

Hi jdevalk

I found your article very interesting but being a novice to this business, especilly away from html/css I am confused.

Basically I have 4 questions:

  1. add the code as it is in the article to my .htaccess without affecting what I have there already
    1. Do I use the php file exactly as it is, and where do I place it? In the root directory?
    2. The redirects.txt seems too simple to me as affiliate code is usually quite long.
    3. And the bigger question: what do I write in my html file instead of the affiliate code?

Thank you very much

qim commented Feb 13, 2014

Hi jdevalk

I found your article very interesting but being a novice to this business, especilly away from html/css I am confused.

Basically I have 4 questions:

  1. add the code as it is in the article to my .htaccess without affecting what I have there already
    1. Do I use the php file exactly as it is, and where do I place it? In the root directory?
    2. The redirects.txt seems too simple to me as affiliate code is usually quite long.
    3. And the bigger question: what do I write in my html file instead of the affiliate code?

Thank you very much

@qim

This comment has been minimized.

Show comment Hide comment
@qim

qim Feb 13, 2014

Well, I decide to go ahead and try. First, when I added the htaccess code I could not open any of my pages; I decided that was because it was looking for the non-existent index.php but after putting that in the root directory again I could not open any page of the site.

I assume that the index.php is not supposed to replace the index.html, right?

qim commented Feb 13, 2014

Well, I decide to go ahead and try. First, when I added the htaccess code I could not open any of my pages; I decided that was because it was looking for the non-existent index.php but after putting that in the root directory again I could not open any page of the site.

I assume that the index.php is not supposed to replace the index.html, right?

@qim

This comment has been minimized.

Show comment Hide comment
@qim

qim Feb 13, 2014

Please ignore the previous two posts (I don't know how to delete them).

I managed to make sense out of it but although I can redirect easily to normal sights, the affiliate code does not worl, probably because, as was mentioned above, that your code does not like question marks in the url.

In the actual link I was testing for a hotel chain, first the url got stuck and did not open anything; when I changed the ? to %3F as suggested above, the page opened but in the affiliate company and not in the advertiser...

Do you have a work-around?

Thank you

qim commented Feb 13, 2014

Please ignore the previous two posts (I don't know how to delete them).

I managed to make sense out of it but although I can redirect easily to normal sights, the affiliate code does not worl, probably because, as was mentioned above, that your code does not like question marks in the url.

In the actual link I was testing for a hotel chain, first the url got stuck and did not open anything; when I changed the ? to %3F as suggested above, the page opened but in the affiliate company and not in the advertiser...

Do you have a work-around?

Thank you

@qim

This comment has been minimized.

Show comment Hide comment
@qim

qim Feb 14, 2014

Please ignore my posts above. I've sorted it our and it works very well. I ignored the .htaccess file because it, somehow, prevented any of my pages to open. In any case I already had in it
Options -Indexes
which stops folders being accessed.
If anyone needs to see what I have done you can see the code in one of the pages, e.g. http://pintotours.net/Europe/Spain/Barcelona.html

Thank you very much.

qim commented Feb 14, 2014

Please ignore my posts above. I've sorted it our and it works very well. I ignored the .htaccess file because it, somehow, prevented any of my pages to open. In any case I already had in it
Options -Indexes
which stops folders being accessed.
If anyone needs to see what I have done you can see the code in one of the pages, e.g. http://pintotours.net/Europe/Spain/Barcelona.html

Thank you very much.

@JonathanR89

This comment has been minimized.

Show comment Hide comment
@JonathanR89

JonathanR89 Jul 22, 2014

I am having trouble with mine. It doesnt seem to be working at all. Not sure what Im doing wrong. Trying to implement it on WordPress. Tried it on a test site of mine and no luck. Last link on this page called "test Link". http://draft.recycling-centers.org/
I created a new folder in my root folder of my site called out and uploaded the files and left the yoast link as a test.
If you could please help.
Thanks

I am having trouble with mine. It doesnt seem to be working at all. Not sure what Im doing wrong. Trying to implement it on WordPress. Tried it on a test site of mine and no luck. Last link on this page called "test Link". http://draft.recycling-centers.org/
I created a new folder in my root folder of my site called out and uploaded the files and left the yoast link as a test.
If you could please help.
Thanks

@vanndigitalnetworks

This comment has been minimized.

Show comment Hide comment
@vanndigitalnetworks

vanndigitalnetworks Aug 10, 2014

So I just put all this (including NGINX script) in my server & I don't see no /out/ links on my website yet. How long before I see a difference???

So I just put all this (including NGINX script) in my server & I don't see no /out/ links on my website yet. How long before I see a difference???

@3mounika

This comment has been minimized.

Show comment Hide comment
@3mounika

3mounika Feb 4, 2015

I have tried this on wordpress blog It's working for me.
But i have lossed what i am getting before.

i.e I am using affiliate links like this - example.com/?affId=123&sid=[currentuser_id](short code plugin) i am getting at the front with current logged in user id example for admin is - example.com/?affId=123&sid=1

But after using this trick i have lossed it, at the front end i am getting mysite.com/out/?id=example, but clicking on that link it will going directly - example.com/?affId=123&sid=currentuser_id

Please help on this. Please

3mounika commented Feb 4, 2015

I have tried this on wordpress blog It's working for me.
But i have lossed what i am getting before.

i.e I am using affiliate links like this - example.com/?affId=123&sid=[currentuser_id](short code plugin) i am getting at the front with current logged in user id example for admin is - example.com/?affId=123&sid=1

But after using this trick i have lossed it, at the front end i am getting mysite.com/out/?id=example, but clicking on that link it will going directly - example.com/?affId=123&sid=currentuser_id

Please help on this. Please

@biscuitgit

This comment has been minimized.

Show comment Hide comment
@biscuitgit

biscuitgit Apr 20, 2015

Thanks so much for this script!

Is it allowed for Amazon affiliate links?

Thanks so much for this script!

Is it allowed for Amazon affiliate links?

@pnb1

This comment has been minimized.

Show comment Hide comment
@pnb1

pnb1 May 21, 2015

I'm sorry, but where exactly I need to put these files? Do I need to append this code to the existing files?

pnb1 commented May 21, 2015

I'm sorry, but where exactly I need to put these files? Do I need to append this code to the existing files?

@kenroar

This comment has been minimized.

Show comment Hide comment
@kenroar

kenroar Jul 29, 2015

@jdevalk
I hope you don't think my questions are stupid. I am not well versed at this. I need to cloak my Amazon affiliate links.

  1. Will the redirect open in a new window or do I have to add the "target=_blank" code in the URL?
  2. Do I have to create a separate script for every affiliate link in the /out/ folder?
    If I need a different redirect for every link would it look something like this?
    default,http://example.com
    amazon,http://www.amazon.com/gp/product/affiliate-code-to-specific-product
    test,http://amazon.com/?p=2
  3. Does the redirect file in the /out/ folder act like CSS where I add something in the original URL in HTML in my pages such as div="redirect"

kenroar commented Jul 29, 2015

@jdevalk
I hope you don't think my questions are stupid. I am not well versed at this. I need to cloak my Amazon affiliate links.

  1. Will the redirect open in a new window or do I have to add the "target=_blank" code in the URL?
  2. Do I have to create a separate script for every affiliate link in the /out/ folder?
    If I need a different redirect for every link would it look something like this?
    default,http://example.com
    amazon,http://www.amazon.com/gp/product/affiliate-code-to-specific-product
    test,http://amazon.com/?p=2
  3. Does the redirect file in the /out/ folder act like CSS where I add something in the original URL in HTML in my pages such as div="redirect"
@ricknoelle

This comment has been minimized.

Show comment Hide comment
@ricknoelle

ricknoelle Sep 2, 2015

Hi @kenroar

  1. It will not open in a new window, but yes, if you use target="_blank" in your link tag (a href=...), it will open in a new link.
  2. No, you don't need a separate script (if you mean PHP script), the single index.php script works for all links, but as you pointed out, you need a unique entry in redirects.txt for each affiliate link.
  3. Not sure what you mean but the redirect file in /out/ is not in any way related to CSS. It simply accepts a target id through the href link in your HTML's a tag and redirects accordingly. Any CSS should be added to the HTML tag. So, an example link would be something like this assuming you use the folder /out/ as Yoast does:
<a href="/out/?id=amazon" target="_blank" class="{whatever css class you want here, nothing to do with the redirect}">Get this product on Amazon</a>

Hi @kenroar

  1. It will not open in a new window, but yes, if you use target="_blank" in your link tag (a href=...), it will open in a new link.
  2. No, you don't need a separate script (if you mean PHP script), the single index.php script works for all links, but as you pointed out, you need a unique entry in redirects.txt for each affiliate link.
  3. Not sure what you mean but the redirect file in /out/ is not in any way related to CSS. It simply accepts a target id through the href link in your HTML's a tag and redirects accordingly. Any CSS should be added to the HTML tag. So, an example link would be something like this assuming you use the folder /out/ as Yoast does:
<a href="/out/?id=amazon" target="_blank" class="{whatever css class you want here, nothing to do with the redirect}">Get this product on Amazon</a>
@jacassidy

This comment has been minimized.

Show comment Hide comment
@jacassidy

jacassidy Dec 29, 2015

@jdevalk,

I’m no PHP expert, but I wanted to change the 302 status code to 307. When I did it, I may have found redundant code here: header( "Location: " . $url, 302 );

First, I attempted to change the current 302 copy to 307. This did nothing. I did a bit of research and then changed the X-Robots-Tag instead:

header( "X-Robots-Tag: noindex, nofollow", true );
Became
header( "X-Robots-Tag: noindex, nofollow", true, 307 );

I also deleted the 302 in the Location tag since it doesn’t seem to have a purpose (The default response is 302 for redirects, so a 302 status is return whether the 302 is in that tag or not):

header( "Location: " . $url, 302 );
Became
header( "Location: " . $url );

All put together I’m now using:

if ( $url ) {
header( "X-Robots-Tag: noindex, nofollow", true, 307 );
header( "Location: " . $url );
die;

Please correct me if there's a purpose for the 302 in the Location tag. As far as I can tell it doesn't create the status code.

Cheers! And thanks for the script.

@jdevalk,

I’m no PHP expert, but I wanted to change the 302 status code to 307. When I did it, I may have found redundant code here: header( "Location: " . $url, 302 );

First, I attempted to change the current 302 copy to 307. This did nothing. I did a bit of research and then changed the X-Robots-Tag instead:

header( "X-Robots-Tag: noindex, nofollow", true );
Became
header( "X-Robots-Tag: noindex, nofollow", true, 307 );

I also deleted the 302 in the Location tag since it doesn’t seem to have a purpose (The default response is 302 for redirects, so a 302 status is return whether the 302 is in that tag or not):

header( "Location: " . $url, 302 );
Became
header( "Location: " . $url );

All put together I’m now using:

if ( $url ) {
header( "X-Robots-Tag: noindex, nofollow", true, 307 );
header( "Location: " . $url );
die;

Please correct me if there's a purpose for the 302 in the Location tag. As far as I can tell it doesn't create the status code.

Cheers! And thanks for the script.

@prof611

This comment has been minimized.

Show comment Hide comment
@prof611

prof611 Apr 24, 2016

I just ran across https://yoast.com/cloak-affiliate-links/ the other day, and since I am somewhat of an expert on link-cloaking, I decided to try out this method myself. It works, but there are two disadvantages compared to the method I recommend, http://scriptsforyourwebsite.professorsopportunities.com/scriptsforwebsites/scripts/hide-your-affiliate-links/ .

(1) There is quite a bit of work involved in setting it up, and the instructions are not very clear in some places,

(2) My method has been around for years, and it is superior to yours in two very important respects: (i) The affiliate ID is not shown in the address bar of the destination URL, and (ii) The destination page may be ANYWHERE - it's not necessary for the user to be redirected to the same URL that appears in the affiliate link.

Please take a look at http://scriptsforyourwebsite.professorsopportunities.com/linkcloakertutorial.html for a 5-step procedure of how to use CloakerBuzz, and an explanation of how it works. And download a free copy to try on your own - it's easy, and it works!

prof611 commented Apr 24, 2016

I just ran across https://yoast.com/cloak-affiliate-links/ the other day, and since I am somewhat of an expert on link-cloaking, I decided to try out this method myself. It works, but there are two disadvantages compared to the method I recommend, http://scriptsforyourwebsite.professorsopportunities.com/scriptsforwebsites/scripts/hide-your-affiliate-links/ .

(1) There is quite a bit of work involved in setting it up, and the instructions are not very clear in some places,

(2) My method has been around for years, and it is superior to yours in two very important respects: (i) The affiliate ID is not shown in the address bar of the destination URL, and (ii) The destination page may be ANYWHERE - it's not necessary for the user to be redirected to the same URL that appears in the affiliate link.

Please take a look at http://scriptsforyourwebsite.professorsopportunities.com/linkcloakertutorial.html for a 5-step procedure of how to use CloakerBuzz, and an explanation of how it works. And download a free copy to try on your own - it's easy, and it works!

@NoIdeaWhatImdoing22

This comment has been minimized.

Show comment Hide comment
@NoIdeaWhatImdoing22

NoIdeaWhatImdoing22 May 6, 2016

Okay, so I have godaddy website builder, and I also have absolutely no clue how to code. I downloaded the files, but where would I even put it? When I add the code to the html code thing it just makes text. I'm so confused

Okay, so I have godaddy website builder, and I also have absolutely no clue how to code. I downloaded the files, but where would I even put it? When I add the code to the html code thing it just makes text. I'm so confused

@Mack86

This comment has been minimized.

Show comment Hide comment
@Mack86

Mack86 Aug 18, 2017

Hi Everyone,
Find this page very interesting!!
I'm new in this cloaking stuff finally reach here.........
Can Someone tell me how to cloak it, I have watch lots of YouTube tutorial but nothing help me..

  1. index.php
  2. .htaccess
  3. redirects.
    In INDEX

Make sure yor redirects.txt file contains a default value, syntax:

default,http://example.com

Where you should replace example.com with your domain.

'; } If my landing page is "youtube.com" where should I change it and the safe page is "google.com" where should I put it Thirdly? which code shoud I use in my index.php for Youtube.com?? Highly appreciate!!

Mack86 commented Aug 18, 2017

Hi Everyone,
Find this page very interesting!!
I'm new in this cloaking stuff finally reach here.........
Can Someone tell me how to cloak it, I have watch lots of YouTube tutorial but nothing help me..

  1. index.php
  2. .htaccess
  3. redirects.
    In INDEX

Make sure yor redirects.txt file contains a default value, syntax:

default,http://example.com

Where you should replace example.com with your domain.

'; } If my landing page is "youtube.com" where should I change it and the safe page is "google.com" where should I put it Thirdly? which code shoud I use in my index.php for Youtube.com?? Highly appreciate!!
@MrFrazSultan

This comment has been minimized.

Show comment Hide comment
@MrFrazSultan

MrFrazSultan Oct 28, 2017

What I did is just upload 3 files into my domain main directory and overwrite .htaccess and replace my domain in redirects.txt and I am getting following error ERR_TOO_MANY_REDIRECTS in chrome browser I didn't create any robots.txt. when redirects.txt was default my domain redirects to example.com.
Will someone please help me to sort this issue?
Thanks.

What I did is just upload 3 files into my domain main directory and overwrite .htaccess and replace my domain in redirects.txt and I am getting following error ERR_TOO_MANY_REDIRECTS in chrome browser I didn't create any robots.txt. when redirects.txt was default my domain redirects to example.com.
Will someone please help me to sort this issue?
Thanks.

@MomBot

This comment has been minimized.

Show comment Hide comment
@MomBot

MomBot Apr 26, 2018

It does what it says on the tin! I had already created a subdomain for my website, which I won't list here, but I simply created a subdomain and named it "go" and then issued a Let's Encrypt SSL certificate for it (because... why not). I created a robots.txt file and yes I did exclude that whole subdomain. Then I uploaded the three files (index.php, .htaccess, and redirects.txt). In the redirects.txt file, I started with my default entry, which is my homepage, and then listed out all my affiliate links. I keep a separate spreadsheet with the raw and cloaked links for all affiliate programs. When I tested the links, they simply worked! I'll now be setting up this same list on all my sites so that they can individually link to the affiliate links smoothly. This rocks! Thank you, Yoast and Github!

Someone advised me to cloak all my outbound links for consistency and because if those links start up an affiliate program later, it's simple to change the entry for that link in the redirects.txt file and then it's done! I also have a couple of affiliate programs that I'm waiting on an approval for. I'll go ahead and write my articles and link to the regular site with the cloaked link, then once the programs are set up, I'll insert my new affiliate link into the redirects.txt file.

One last note: the question marks in my links did not require special handling as someone noted above. I left them in place and the links worked as desired. Color me one happy camper!

MomBot commented Apr 26, 2018

It does what it says on the tin! I had already created a subdomain for my website, which I won't list here, but I simply created a subdomain and named it "go" and then issued a Let's Encrypt SSL certificate for it (because... why not). I created a robots.txt file and yes I did exclude that whole subdomain. Then I uploaded the three files (index.php, .htaccess, and redirects.txt). In the redirects.txt file, I started with my default entry, which is my homepage, and then listed out all my affiliate links. I keep a separate spreadsheet with the raw and cloaked links for all affiliate programs. When I tested the links, they simply worked! I'll now be setting up this same list on all my sites so that they can individually link to the affiliate links smoothly. This rocks! Thank you, Yoast and Github!

Someone advised me to cloak all my outbound links for consistency and because if those links start up an affiliate program later, it's simple to change the entry for that link in the redirects.txt file and then it's done! I also have a couple of affiliate programs that I'm waiting on an approval for. I'll go ahead and write my articles and link to the regular site with the cloaked link, then once the programs are set up, I'll insert my new affiliate link into the redirects.txt file.

One last note: the question marks in my links did not require special handling as someone noted above. I left them in place and the links worked as desired. Color me one happy camper!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment