To find broken affiliate links, you first need a complete list of every affiliate link on your site and the pages it sits on. Then you check each one for errors, and finally you look at where the working ones actually land. Most guides skip the first step and go straight to "click every link". That's fine for ten posts and hopeless for three hundred.
This guide walks through all three steps. It covers the free, manual way first, then a script that builds the list for you, then how to keep checking without thinking about it. Along the way you'll see the failures a simple status check catches, and the ones it can't.
Why broken affiliate links cost more than other broken links
A broken link in a blog post is a bad experience. A broken affiliate link is a bad experience and lost money. You keep paying for it until someone notices.
Three things make affiliate links especially costly:
- They sit on your best pages. Affiliate links cluster in reviews, comparisons and "best X" roundups. Those are the pages that rank and get traffic, so a dead link there gets clicked over and over.
- Nobody tells you. A reader who hits a 404 on a merchant's site doesn't email you. They hit back and buy somewhere else, or buy through someone else's link.
- Your reports hide it. Your affiliate dashboard shows clicks and commissions, not "clicks that went nowhere". A slow drop in earnings looks like seasonality until you check.
How affiliate links break
Knowing how links fail tells you what to look for. Here are the common causes, roughly from most to least obvious:
| What happened | What the visitor sees | What a link checker sees |
|---|---|---|
| Merchant deleted the product page | "Page not found" | 404 or 410 |
| Merchant restructured its URLs without redirects | "Page not found" | 404 |
| The affiliate program closed or the merchant left the network | An error page from the network, or nothing | 404, 5xx, or a redirect to a generic page |
| The merchant's domain expired | A parked page, or the browser can't connect | DNS failure, or 200 on a parked page |
| The merchant's server is down or overloaded | An error or endless spinner | 5xx or a timeout |
| Product out of stock or discontinued, page kept live | A product page you can't buy from | 200 (looks fine) |
| Link redirects to the homepage or a category page | A page that isn't what you promised | 200 after a redirect (looks fine) |
| Your tracking ID is missing or wrong | A normal product page | 200 (looks fine), but you aren't credited |
The first five rows are hard failures: the link returns an error code or nothing at all. A status-code check catches them every time, and they're usually the most expensive because the visitor gets nothing.
The last three are soft failures. The page loads with a 200 OK, so no status checker will flag it. You catch these by looking at the landing page, which we'll cover in Method 1. Plan for both, but fix the hard failures first.
If you want a refresher on what each status code means, see How to Find and Fix Broken Links on Your Website.
Step 1: build a list of every affiliate link
You can't check links you don't know about. Before any method below, get a list with two columns: the affiliate URL, and the pages it appears on.
If you use a link-cloaking plugin (Pretty Links, ThirstyAffiliates and similar), you already have most of the list. Those plugins store every cloaked link (yoursite.com/go/product-name) in one table you can usually export. The catch: raw affiliate links pasted straight into posts aren't in that table.
If your links are spread across posts, use a crawler or the script below. (On WordPress, a link-checker plugin can also list them. If the usual plugin is too heavy for your host, see Broken Link Checker plugin alternatives.) It reads your sitemap, opens every page, and saves every link that matches the affiliate patterns you set to a CSV, along with the pages each one appears on. It uses only Python's standard library, so there's nothing to install.
#!/usr/bin/env python3
"""List every outbound affiliate link on a site, with the pages it appears on.
Usage: python3 find_affiliate_links.py https://example.com/sitemap.xml > affiliate-links.csv
"""
import csv
import re
import sys
import urllib.request
import xml.etree.ElementTree as ET
from html.parser import HTMLParser
from urllib.parse import urljoin
# Edit these to match the networks and cloaking prefixes you use.
AFFILIATE_PATTERNS = [
r"amazon\.[a-z.]+/.*[?&]tag=", # Amazon Associates links carry your tag= parameter
r"amzn\.to/", # Amazon short links
r"/go/", r"/recommends/", r"/refer/", # common cloaked-link prefixes
r"shareasale\.com", r"awin1\.com", r"impact\.com", r"partnerize", r"cj\.com",
]
AFFILIATE_RE = re.compile("|".join(AFFILIATE_PATTERNS), re.I)
NS = {"sm": "http://www.sitemaps.org/schemas/sitemap/0.9"}
UA = "Mozilla/5.0 (compatible; affiliate-link-audit/1.0)"
def get(url):
req = urllib.request.Request(url, headers={"User-Agent": UA})
with urllib.request.urlopen(req, timeout=20) as r:
return r.read().decode("utf-8", errors="replace")
def sitemap_urls(url):
root = ET.fromstring(get(url))
if root.tag.endswith("sitemapindex"):
for loc in root.findall("sm:sitemap/sm:loc", NS):
yield from sitemap_urls(loc.text.strip())
else:
for loc in root.findall("sm:url/sm:loc", NS):
yield loc.text.strip()
class LinkParser(HTMLParser):
def __init__(self):
super().__init__()
self.links = []
def handle_starttag(self, tag, attrs):
if tag == "a":
href = dict(attrs).get("href")
if href:
self.links.append(href)
found = {} # affiliate URL -> set of pages it appears on
for page in sitemap_urls(sys.argv[1]):
try:
parser = LinkParser()
parser.feed(get(page))
except Exception as e:
print(f"skipped {page}: {e}", file=sys.stderr)
continue
for href in parser.links:
url = urljoin(page, href)
if AFFILIATE_RE.search(url):
found.setdefault(url, set()).add(page)
writer = csv.writer(sys.stdout)
writer.writerow(["affiliate_url", "pages", "page_count"])
for url, pages in sorted(found.items(), key=lambda kv: -len(kv[1])):
writer.writerow([url, " ".join(sorted(pages)), len(pages)])A few notes before you run it:
- Edit
AFFILIATE_PATTERNSfirst. The defaults are examples. Add the domains your networks use and your own cloaking prefix if it isn't/go/. A pattern that's too broad (justamazon.com, say) will also pick up plain, non-affiliate links. - It reads the HTML your server sends. Links injected later by JavaScript (some widgets and comparison-table plugins do this) won't show up. Open one page's source (
Ctrl+U) and search for a link you can see on the page to confirm. - It trusts your sitemap. Pages missing from the sitemap won't be scanned, and dead entries get skipped. Check your sitemap for 404s first if you haven't recently.
- Sort by
page_count. A link that appears on 40 pages is usually in a template, sidebar or reusable block. Fix it once and you've fixed 40 pages.
Now you have a spreadsheet. Add two columns, status and notes, and pick a method.
Method 1: check your top-earning pages by hand
Best for: small sites, and the soft failures no tool catches.
Manual checking doesn't scale, but it's the only way to catch the 200 OK problems from the table above. Do it for the pages that earn the most, not for everything.
- Pick your top 20 pages. Use your affiliate network's reports by sub-ID if you tag links that way. If you don't, use your analytics to find the highest-traffic pages that contain affiliate links.
- Open each link in a private window. Private browsing drops your cookies and cached redirects, so you see what a new visitor sees.
- Watch the address bar through every redirect. Affiliate links often hop through a tracking domain or two before the merchant. Note where you finally land.
- Confirm the landing page is what your post promised. The right product, in stock, with a working buy button. Not the homepage, not a category page, not "currently unavailable".
- Check your tracking ID survived. For Amazon, the final URL should still carry your
tag=value. Amazon also has a Link Checker in Associates Central that confirms whether a link is tagged to your account. For other networks, compare the publisher ID in the link with the one in your dashboard. - Write down what you find in the
notescolumn, then fix the worst ones first.
Budget about a minute per link. Twenty pages with five links each is under two hours. Do it quarterly and after any merchant tells you they're relaunching their site.
Method 2: bulk-check status codes once
Best for: finding every hard failure on a site of any size, today.
Feed the list from Step 1 to anything that requests each URL and records the response. A minimal version with curl, which prints only the failures:
# affiliate-links.txt: one URL per line (the first column of your CSV)
while read -r url; do
code=$(curl -o /dev/null -s -L --max-time 15 -w "%{http_code}" "$url")
if [ "$code" = "000" ] || [ "$code" -ge 400 ]; then
echo "$code $url"
fi
sleep 1
done < affiliate-links.txt-L follows redirects, so you get the status of the page the visitor finally lands on, not the first tracking hop. 000 means curl got no HTTP response at all, which usually points to a timeout or a domain that no longer resolves.
How to read what comes back:
404/410: the destination is gone. Replace the link or remove it.5xxor000once: could be a bad minute on their side. Re-check tomorrow before changing anything.5xxor000for several days running: treat it as dead.403/429: often a bot wall or rate limit, not a broken page. Open it in a browser before you touch it.
The weakness of a one-time check is in the name. It tells you about today. Merchants delete products and close programs on their own schedule, and a list that was clean on Monday can have a dead link by Friday.
Method 3: monitor affiliate links daily
Best for: anyone whose affiliate income is worth protecting.
The money in affiliate links is in catching breaks quickly. Finding them eventually isn't enough. A link that dies on the 3rd and gets found at your monthly review has spent four weeks earning nothing on your best pages. A daily check cuts that down to a day.
You can run the curl loop from Method 2 on a schedule (see How to Monitor Broken Links Automatically for a cron and Slack setup). Or you can use a hosted monitor so there's no script to maintain.
This is what Brokenlink does. You paste your affiliate URLs, the first column of the CSV from Step 1, into a project. Every link is then rechecked every 24 hours. When one starts returning a 4xx or 5xx, times out, or its domain stops resolving, you get an email or Slack alert with the exact URL and error code. A few things that help with affiliate work specifically:
- Labels. Tag links by network, merchant or campaign, so "everything from merchant X is failing" stands out at a glance.
- Projects. Keep each site, or each client if you manage several, separate.
- Status history. Each link keeps 30 days of check results. You can see a link that fails every few days, which usually means a struggling merchant, before it dies for good.
To be clear about the limits: like any status-code check, Brokenlink flags the hard failures in the table above. It won't tell you a product is out of stock, or that a working link lost your tracking tag. Keep the quarterly manual pass from Method 1 for those.
Fixing broken affiliate links
Once you've found them, the fix depends on what broke:
- The product moved. Find the new product URL on the merchant's site and generate a fresh affiliate link from your network dashboard. Don't hand-edit the old link. Generating a new one keeps your tracking parameters correct.
- The product is discontinued. Point the link at the closest current equivalent, and update the copy around it. Recommending a different product without saying so hurts your credibility more than the dead link did.
- The program closed. Check whether the merchant moved to another network you belong to. If not, look for a comparable merchant with an active program, or link to the product without a commission.
- The merchant is gone. Remove the link, and rework the section if the recommendation no longer stands.
- The link appears on many pages. If you use a cloaking plugin, update the destination of the cloaked link once and every page that uses it is fixed. That's the main argument for cloaking.
After fixing, re-run your check on the changed links to confirm they resolve, and keep them in your monitoring list.
A simple routine that works
| When | What to do | Time |
|---|---|---|
| Once | Build the full affiliate link list (Step 1) | 30–60 minutes |
| Every day | Automated status check with alerts (Method 3) | None after setup |
| When an alert arrives | Fix or replace the link | Minutes |
| Every quarter | Manual check of your top 20 earning pages (Method 1) | 1–2 hours |
| After publishing | Add new affiliate links to your monitored list | Seconds per post |
| When a merchant relaunches its site | Manual check of every link to that merchant | Varies |
For how this fits into a check schedule for the rest of your site, see How Often Should You Check for Broken Links?
The short version
- Affiliate links fail in two ways: hard (
404,5xx, timeouts, dead domains) and soft (out of stock, redirected to the homepage, tracking tag lost). - Start by building a list of every affiliate link and the pages it lives on. The script above does it from your sitemap.
- Bulk-check status codes to find every hard failure today, and check your top 20 pages by hand to catch the soft ones.
- Links keep breaking after your audit, so check them daily. Brokenlink rechecks every link every 24 hours and alerts you by email or Slack. Plans start at $9/month for 1,000 links, with a 14-day free trial and no card required (pricing).