# Amazon link rewriting for affiliate codes

**URL:** https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174
**Category:** Feature
**Created:** [24 Gennaio 2014, 5:40pm UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174 "2014-01-24T17:40:26Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![dean](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@dean](https://meta.discourse.org/u/dean)
#### Post date: [22 Agosto 2014, 10:46pm UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/22 "2014-08-22T22:46:32Z")

</div>

I’ve adapted Affililink to work on Discourse, please let me know any feedback you may have.

[https://github.com/deanbarrow/discourse\_affililink](https://github.com/deanbarrow/discourse_affililink)

---

<div class="post-metadata">

### Author: ![geek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/geek/32/102154_2.png) [@geek](https://meta.discourse.org/u/geek)
#### Post date: [27 Agosto 2014, 11:31pm UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/23 "2014-08-27T23:31:29Z")

</div>

I would really love to see something integrated into Discourse to strip out the affiliate codes.

Just figured out that one of my forum users has been sneaking Amazon affiliate codes into links and I didn’t notice until just now. I’m guessing there are others that I didn’t realize.

And my forum is tiny.

---

<div class="post-metadata">

### Author: ![dean](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@dean](https://meta.discourse.org/u/dean)
#### Post date: [27 Agosto 2014, 11:53pm UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/24 "2014-08-27T23:53:46Z")

</div>

This will strip out and replace other users links. It’s automatically run client side rather than built into Discourse but does the job all the same.

---

<div class="post-metadata">

### Author: ![geek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/geek/32/102154_2.png) [@geek](https://meta.discourse.org/u/geek)
#### Post date: [27 Agosto 2014, 11:58pm UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/25 "2014-08-27T23:58:02Z")

</div>

Does it work for amzn.to links?

---

<div class="post-metadata">

### Author: ![dean](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@dean](https://meta.discourse.org/u/dean)
#### Post date: [28 Agosto 2014, 12:23am UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/26 "2014-08-28T00:23:46Z")

</div>

It will work with any link structured: [domain.com/blah/?var=affcode](http://domain.com/blah/?var=affcode)

As long as you set it in the config, this means it’ll work with most affiliate schemes out there.

---

<div class="post-metadata">

### Author: ![geek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/geek/32/102154_2.png) [@geek](https://meta.discourse.org/u/geek)
#### Post date: [28 Agosto 2014, 12:36am UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/27 "2014-08-28T00:36:51Z")

</div>

So… it won’t work with amzn.to links then.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [28 Agosto 2014, 1:14am UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/28 "2014-08-28T01:14:34Z")

</div>

Looks like it would, you may need to alter the universal codes to add amzn.to.

See lines 16-25

> <https://github.com/deanbarrow/discourse_affililink/blob/master/assets/javascripts/affililink.js>

---

<div class="post-metadata">

### Author: ![geek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/geek/32/102154_2.png) [@geek](https://meta.discourse.org/u/geek)
#### Post date: [28 Agosto 2014, 1:28am UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/29 "2014-08-28T01:28:14Z")

</div>

amzn.to is their custom link shortener. It’s not going to work.

---

<div class="post-metadata">

### Author: ![fysics](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fysics/32/34080_2.png) [@fysics](https://meta.discourse.org/u/fysics)
#### Post date: [28 Agosto 2014, 3:50am UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/30 "2014-08-28T03:50:56Z")

</div>

> [@geek](#):
>
> amzn.to is their custom link shortener. It’s not going to work.

amzn.to is operated by bit.ly. It can be done. The steps would be:

1. Resolve amzn.to link into full link. (Using curl or some similar method.)
2. Make adjustments to the url as necessary.
3. (optional) Reshorten the link using bit.ly. [Amazon.com](http://Amazon.com) links are automatically shortened into amzn.to links.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [28 Agosto 2014, 4:39am UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/31 "2014-08-28T04:39:31Z")

</div>

Was this user shortening to amzn.to links that included an affiliate code?

---

<div class="post-metadata">

### Author: ![geek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/geek/32/102154_2.png) [@geek](https://meta.discourse.org/u/geek)
#### Post date: [28 Agosto 2014, 4:40am UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/32 "2014-08-28T04:40:45Z")

</div>

Yes, and that user has been yelled at and I am still mulling the idea of banning him.

---

<div class="post-metadata">

### Author: ![geek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/geek/32/102154_2.png) [@geek](https://meta.discourse.org/u/geek)
#### Post date: [28 Agosto 2014, 4:45am UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/33 "2014-08-28T04:45:10Z")

</div>

Honestly, I think that adjusting affiliate links could be a core feature for offering non-intrusive advertising. It would be a good selling point.

I mean, it could be implemented as a plugin, but offered as part of your hosting service as a premium feature.

---

<div class="post-metadata">

### Author: ![dean](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@dean](https://meta.discourse.org/u/dean)
#### Post date: [28 Agosto 2014, 6:54am UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/34 "2014-08-28T06:54:34Z")

</div>

Yes of course it will. Check the config for for a better idea of how it works.

---

<div class="post-metadata">

### Author: ![geek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/geek/32/102154_2.png) [@geek](https://meta.discourse.org/u/geek)
#### Post date: [28 Agosto 2014, 7:04am UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/35 "2014-08-28T07:04:43Z")

</div>

Alrighty then. Show me how it will replace the code in this affiliate link:

[http://amzn.to/1lxzAnl](http://amzn.to/1lxzAnl)

---

<div class="post-metadata">

### Author: ![dean](https://avatars.discourse-cdn.com/v4/letter/d/3be4f8/32.png) [@dean](https://meta.discourse.org/u/dean)
#### Post date: [28 Agosto 2014, 8:29am UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/36 "2014-08-28T08:29:25Z")

</div>

Right, I see what you mean. Just played around with it and it seems the tag is overwritten when converted.

The ideal way would be to expand each link server side and process the code there, and then it can be stored as an affiliate link in the database. I’m not really looking to pursue this though as my aim is to keep the affililink project as universal as possible without being locked into a specific platform.

I used to have a hosted version similar to viglink/skimlinks which would do this, however decided to abandon that project.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [28 Agosto 2014, 5:59pm UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/37 "2014-08-28T17:59:57Z")

</div>

Another, related problem: How would you rewrite an adf.ly link?

Actually, that brings up the point of banning all links to a certain domain, even by trusted users. We have `/admin/logs/screened_urls`, but judging from the `screened_url_spec` and the UI, it’s mostly there to watch the spammers and know when we need to eventually implement something. (Basically, “it does nothing yet”.)

---

<div class="post-metadata">

### Author: ![geek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/geek/32/102154_2.png) [@geek](https://meta.discourse.org/u/geek)
#### Post date: [28 Agosto 2014, 6:05pm UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/38 "2014-08-28T18:05:57Z")

</div>

> [@riking](#):
>
> Actually, that brings up the point of banning all links to a certain domain

Yeah, I’d love to ban all short links and force people to post the real links. Or automatically expand short links.

And I’d love to ban known ad links.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [28 Agosto 2014, 10:01pm UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/39 "2014-08-28T22:01:38Z")

</div>

It seems like this is the underlying feature request, and one I agree with because I have heard it before from multiple sources…

---

<div class="post-metadata">

### Author: ![geek](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/geek/32/102154_2.png) [@geek](https://meta.discourse.org/u/geek)
#### Post date: [28 Agosto 2014, 11:30pm UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/40 "2014-08-28T23:30:35Z")

</div>

The underlying problem is that I don’t want users trying to make money by sneaking in advertising links or affiliate links, and I don’t want other users or readers having to wonder what they are clicking on.

And right now there’s no way for me to deal with this problem other than just seeing what people are linking to.

---

<div class="post-metadata">

### Author: ![CamilleRoux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/camilleroux/32/119575_2.png) [@CamilleRoux](https://meta.discourse.org/u/CamilleRoux)
#### Post date: [2 Settembre 2014, 1:38pm UTC](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174/41 "2014-09-02T13:38:58Z")

</div>

I made a plugin (alpha version): [GitHub - camilleroux/discourse-affiliate · GitHub](https://github.com/camilleroux/discourse-affiliate)

Enjoy and feel free to send pull requests to improve it 🙂

[Previous page](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174.md?page=1)

[Next page](https://meta.discourse.org/t/amazon-link-rewriting-for-affiliate-codes/12174.md?page=3)
