# Links & Redirects

Links & Redirects reference: requirements, settings, 12 agent tools with full notes, and core events, read from the code.

Affiliate links at /go/… with groups, click analytics and automatic rel="sponsored nofollow" tags, plus redirects and a 404 monitor with one-click fixes.

**Beta.** Links & Redirects is in beta: it works, but things may still break. If something breaks, [report it](https://github.com/sundoggs/support/issues/new).

On the store: [Links & Redirects](https://sundo.gs/apps/links) in [SEO and links](https://sundo.gs/categories/seo), [pricing](https://sundo.gs/pricing).

## Price

$19 USD per site · $59 USD for all your sites, paid once. Every purchase includes 12 months of updates, and there is a full refund within 7 days. Details: [pricing](https://sundo.gs/pricing).

## Requirements

- Cloudflare® plan: Cloudflare free plan
- Works on: Cloudflare Workers; Cloudflare Pages; A site on its own server (VPS or cloud) with DNS on Cloudflare, through a Worker route in front of it (beta, tested on a live server) ([hosts](https://sundo.gs/docs/hosts.md))
- Version: 0.13.10 (needs core 0.29.0 or later; it comes in the same download)
- Runs on the Cloudflare free plan. Uses one D1 database in your account.
- Works with any framework: static sites on Pages or Workers, and server-rendered sites on Workers (Astro with @astrojs/cloudflare, Next.js with OpenNext, or any site with its own Worker). Not yet supported: Pages sites with their own \_worker.js.
- Page views run through the app so it can tag affiliate links automatically; images, CSS, JS and fonts are served directly. Page views count toward the Cloudflare free 100,000 requests/day (Workers Paid, $5/mo, removes the daily cap).
- Link health checks make a few outside requests to your partners' destination URLs (not to us), at most 40 per run, once a day by default. Turn them off in Settings, or per link. The partner may count the visit; it never counts as a click on your site.
- Automatic link tagging can be switched off in the site admin; on Workers that returns page views to free, unlimited static serving.
- Cost per visit: page views add no requests and no writes. A /go/ click is 2 small writes (the count and the click event); repeated 404s are added up in memory and saved at most once a minute per path. If the Cloudflare free database limit is reached, logging pauses and links keep redirecting. Visit sources are counted by core: page views are added up in memory and saved in a few small writes about every 20 seconds, within the daily write budget; at the Cloudflare free limits counting pauses and the site is unaffected.

## What it adds to the site

- Addresses it answers: `/go/*`
- Edits pages as they are served: yes
- Has a say when a page is not found: yes
- Uses the site's [brand](https://sundo.gs/docs/core.md#brand): no
- Database tables (in the site's own D1 database): `links_links`, `links_redirects`, `links_not_found`, `links_scan`, `links_usage`, `links_labels`, `links_health`

## Agent tools

Links & Redirects adds 12 tools to the site's own [agent connection](https://sundo.gs/docs/agent-connection.md). The short text under each name is what an agent sees in its tool list; the full notes are what `site_tool_help` returns. The [shared rules](https://sundo.gs/docs/core/site-tools.md#shared-rules) for `confirm`, `dry_run` and `on` apply to every tool.

### Read (changes nothing)

#### `links_list`

List the site's /go/ short links with destination, redirect type, group, clicks and on/off; variants are listed with their parent. Use before creating a link, to avoid duplicates. One link in full: links_get.

Read only: changes nothing.

| Field | Type | Required | What it is |
|---|---|---|---|
| `group` | string | no | Only links in this group. |
| `search` | string | no | Only links whose short name or destination contains this text. |
| `limit` | integer | no | Default 200. |
| `offset` | integer | no | Skip this many (next page). Pass the `next.offset` of the previous answer. |

#### `links_get`

One link in full, exactly as links_save takes it, so you can change only what needs it.

Read only: changes nothing.

**Full notes** (what `site_tool_help` returns):

Fields: slug, target, status, group, note, fallback_url, sub_ids, unknown_variants, health_check, and for a variant parent_slug, variant and dest_mode.

| Field | Type | Required | What it is |
|---|---|---|---|
| `id` | integer | no |  |
| `slug` | string | no | The short name after /go/. |

#### `links_redirects`

List the site's redirects (old path to new URL) with type, hits and last hit, newest first. Long lists come in pages: the answer's `next` says the call for the next one.

Read only: changes nothing.

| Field | Type | Required | What it is |
|---|---|---|---|
| `limit` | integer | no | Default 200. |
| `offset` | integer | no | Skip this many (next page). Pass the `next.offset` of the previous answer. |

#### `links_not_found`

Pages visitors asked for that don't exist (404s), most requested first, with bot counts and the last referrer. Fix real ones with links_404_redirect; hide noise with links_404_ignore. Paged: `next` gives the next call.

Read only: changes nothing.

| Field | Type | Required | What it is |
|---|---|---|---|
| `ignored` | boolean | no | List the ignored ones instead. |
| `limit` | integer | no | Default 50. |
| `offset` | integer | no | Skip this many (next page). Pass the `next.offset` of the previous answer. |

### Change

#### `links_save`

Create a /go/\<slug\> link (slug and target; for a variant like /go/bluehost/newsletter, parent_slug and variant) or change one (id, or the slug with update:true, plus only what changes: PATCH). The answer's data.url is the short link to use on the site.

Changes the site.

**Full notes** (what `site_tool_help` returns):

PATCH: everything you leave out keeps its saved value; read the current values with links_get. To rename a link send its id with the new slug. dry_run:true shows the merged result without saving. Creating the same destination twice only warns. A variant (one placement of a link) follows the parent's destination unless you give its own target.

| Field | Type | Required | What it is |
|---|---|---|---|
| `id` | integer | no | Change this link. Leave out to create. |
| `slug` | string | no | Short name after /go/: letters, digits, dashes, underscores (a slash only for variants). A slug that already exists is refused unless you send id or update:true. |
| `update` | boolean | no | true: the slug names an existing link to change (same as sending its id). Without it, a slug that already exists is refused. |
| `target` | string | no | Destination URL (https://...). The partner's full affiliate link. |
| `status` | `301`, `302`, `307`, `308` | no | Redirect type: 302 temporary (default for affiliate links), 301 permanent. |
| `group` | string | no | Optional group, e.g. the partner's name, for filtering and reports. |
| `note` | string | no |  |
| `parent_slug` | string | no | Create a variant of this link (with variant). |
| `variant` | string | no | The variant's name, e.g. "newsletter". |
| `dest_mode` | `"same"`, `"own"` | no | Variants: use the parent's destination (same) or give its own target (own). |
| `sub_ids` | object | no | A free map of sub-ID parameters added to the destination, e.g. {"clickref":"{variant}"} ({variant}, {slug}, {page} work). Replaces the whole map. |
| `fallback_url` | string | no | Where to send people if the destination is dead. Empty string removes it. |
| `health_check` | boolean | no | true: check the destination regularly. false: never (no problem shown, no fallback used). |
| `unknown_variants` | `"404"`, `"parent"` | no | Unknown /go/\<slug\>/\<label\> addresses: show a 404, or send to this link and record the label. |
| `dry_run` | boolean | no | true: save nothing; answers wouldSave (the full record) and the warnings. |

#### `links_toggle`

Turn a link off or back on. A link that is off answers 404 until turned on. Without `on` it flips, which is not safe to retry. Check the result with links_list.

Changes the site.

| Field | Type | Required | What it is |
|---|---|---|---|
| `id` | integer | no |  |
| `slug` | string | no | The short name after /go/. Use this or id. |
| `on` | boolean | no | true: on, false: off. Sets the state (safe to retry). |

#### `links_delete`

Delete a /go/ link and all its variants. Anyone with the old short link will get a 404. DESTRUCTIVE: does nothing until called again with confirm:true.

Changes the site. Destructive: does nothing until it is called again with `confirm`.

| Field | Type | Required | What it is |
|---|---|---|---|
| `id` | integer | no |  |
| `slug` | string | no | The short name after /go/. Use this or id. |
| `confirm` | boolean | no | Leave out first (the answer says what would happen); then true, with confirm_token. |
| `confirm_token` | string | no | The answer's confirmToken, sent with confirm:true and the same input. |

#### `links_redirect_add`

Redirect one exact old path to a new page or URL (301 by default), only when the old path isn't a real page. Wildcards are refused: keep them in the \_redirects file, or add each path.

Changes the site.

**Full notes** (what `site_tool_help` returns):

Query strings are carried over. Wildcards look like /blog/\* or /news/:splat. A target on another site is saved with a warning.

| Field | Type | Required | What it is |
|---|---|---|---|
| `from` | string | yes | The old path, e.g. /old-page. |
| `to` | string | yes | A path (/new-page) or a full URL. |
| `status` | `301`, `302`, `307`, `308` | no | Redirect type: 302 temporary (default for affiliate links), 301 permanent. |
| `note` | string | no |  |

#### `links_redirect_delete`

Delete a redirect. The old path will answer 404 again (unless a page exists there). DESTRUCTIVE: does nothing until called again with confirm:true.

Changes the site. Destructive: does nothing until it is called again with `confirm`.

| Field | Type | Required | What it is |
|---|---|---|---|
| `id` | integer | yes |  |
| `confirm` | boolean | no | Leave out first (the answer says what would happen); then true, with confirm_token. |
| `confirm_token` | string | no | The answer's confirmToken, sent with confirm:true and the same input. |

#### `links_404_redirect`

Fix a missing page by redirecting it (301) to the right page. Remove it from the 404 list.

Changes the site.

| Field | Type | Required | What it is |
|---|---|---|---|
| `from` | string | yes | The missing path from links_not_found. |
| `to` | string | yes | A path or full URL. |

#### `links_404_ignore`

Hide a missing path from the 404 list (scanner noise, pages that should stay gone). Undo with links_404_unignore.

Changes the site.

| Field | Type | Required | What it is |
|---|---|---|---|
| `path` | string | yes |  |

#### `links_404_unignore`

Put an ignored missing path back on the open 404 list.

Changes the site.

| Field | Type | Required | What it is |
|---|---|---|---|
| `path` | string | yes |  |

## Core events

- Reports as conversions: `links.click` (Link clicked)

How events work: [core events](https://sundo.gs/docs/core.md#events).

## Works with your other apps

Connects with no setup, in any install order: [SEO Pack](https://sundo.gs/docs/apps/seo.md), [Analytics](https://sundo.gs/docs/apps/analytics.md), [Tag Manager](https://sundo.gs/docs/apps/tags.md), [Social Proof](https://sundo.gs/docs/apps/proof.md).

---

This page on the web: https://sundo.gs/docs/apps/links/
