# Redirects

Redirects map one browser-relative path to another inside a publication. The API returns a redirect record; it does not send an HTTP redirect response itself.

## Authentication

Management routes require a bearer token and the listed capability. `/redirect/resolve` is public. Use `redirect_id` when available; otherwise management routes need a publication selector and `source_path`.

## Routes

| Route | Methods | Authorization | Required input | Optional input and behavior | Success result |
| --- | --- | --- | --- | --- | --- |
| `/redirect/list` | `GET`, `POST` | `redirect.list` | Publication selector | Pagination | Paginated `redirects`. |
| `/redirect/get` | `POST` | `redirect.list` | `redirect_id`, or publication selector plus `source_path` | — | `redirect`. |
| `/redirect/save` | `POST` | `redirect.save` | Create: publication selector, `source_path`, `destination_path`; update: `redirect_id` | `status_code` | Saved `redirect`. |
| `/redirect/delete` | `POST` | `redirect.delete` | `redirect_id`, or publication selector plus `source_path` | — | Deleted `redirect_id`. |
| `/redirect/resolve` | `GET`, `POST` | None | Publication selector, `source_path` | — | Public `redirect`. |

## Save fields

| Field | Required | Type | Description |
| --- | --- | --- | --- |
| `redirect_id` | No | UUID | Updates this redirect. Omit to create. |
| `publication_id` / `publication_slug` | Required on create and public resolve | UUID / String | Selects the publication. |
| `source_path` | Yes on create | String | Browser-relative source path. |
| `destination_path` | Yes on create | String | Browser-relative destination path. |
| `status_code` | No | `301`, `302`, `307`, or `308` | Defaults to `301` when creating. |

```bash
curl -sS https://api.blog.service.m7.org/v1/redirect/save \
  -H 'Authorization: Bearer ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
    "publication_slug":"engineering-notes",
    "source_path":"/old-release-notes",
    "destination_path":"/release-notes",
    "status_code":301
  }'
```

Paths are normalized with one leading slash and no trailing slash except `/`. They cannot contain whitespace, backslashes, query strings, fragments, `.` or `..` segments, or a URL scheme. A source path is unique within its publication and must differ from the destination. The API rejects loops and chains deeper than 32 redirects with `409`.

## Public resolution

```json
{
  "publication_slug": "engineering-notes",
  "source_path": "/old-release-notes"
}
```

```json
{
  "redirect": {
    "source_path": "/old-release-notes",
    "destination_path": "/release-notes",
    "status_code": 301
  }
}
```

After a successful resolve, the caller performs the browser redirect using the returned `destination_path` and `status_code`. An unknown path returns `404`.
