# POST /domains/{name}/redirects

First published 3 Oct 2026 (release 0.1.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the domains group.

Add a path redirect to a domain

- Who may call it: administrator, reseller, customer
- Token scope, any of: domains, all
- Answers: 201 Created

Set source to a path on the domain, such as /old. The match field defaults to prefix, which matches the source path and all paths beneath it. A prefix redirect with source set to / matches the entire site. Use exact to match only the specified path.

Set target to a path starting with / on the same domain or to an absolute HTTP or HTTPS URL. Omit query strings and fragments from target. The redirect preserves the incoming query string by default. Set keep_query to false to drop it. The code defaults to 301 for a permanent redirect. Use 302 for a temporary redirect.

A prefix redirect rejects a target on the same domain given as a path equal to or beneath its source path. Each source path can have one redirect of each match type. The response contains the updated redirects list.

An unknown domain returns 404. Access to an existing domain is limited to administrators, the domain owner and the owner's reseller. Other callers receive 403.

## As a command

- [urbestack-domain-redirect-add](https://urbestack.com/docs/commands/urbestack-domain-redirect-add.md): Adds an HTTP redirect from a path on a domain.

## Parameters

- `name` (path, DomainName, required)

## Request body

JSON, the type [RedirectCreate](https://urbestack.com/docs/api/types/RedirectCreate.md).

- `source` (string, up to 512 characters, required)
- `target` (string, up to 2048 characters, required)
- `code` (integer, one of 301, 302)
- `keep_query` (boolean)
- `match` (string, one of prefix, exact)

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X POST "$API/domains/example.com/redirects" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "code": 301,
    "keep_query": true,
    "match": "prefix",
    "source": "/old",
    "target": "https://example.com/new"
  }'
```

Response, 201 Created:

```
{
  "redirects": [
    {
      "code": 1,
      "created_at": "2026-09-09T10:15:00Z",
      "id": 1,
      "keep_query": true,
      "match": "text",
      "source": "/old",
      "target": "https://example.com/new"
    }
  ]
}
```

## Errors

- 400: Domain name required
- 400: Domain name too long
- 400: Invalid boolean
- 400: Invalid domain name
- 400: Invalid path
- 400: Path may not climb out with ..
- 400: Path may not start with //
- 400: Path required
- 400: Redirect code must be 301 or 302
- 400: Redirect match must be prefix or exact
- 400: Redirect target must be a path starting with / or an http(s) URL
- 400: Redirect target required
- 400: That redirect would point at itself
- 401: Authentication required
- 403: Insufficient privileges
- 404: Domain '<name>' not found
- 409: A <match> redirect for '<source>' already exists
