# redirects

Canonical URL: https://developers.iagenify.com/sdk/ref/domain/redirects/
Language: en

`domain.redirects.add({ from, to, status, keepPath, keepQuery })`

Sends one name of the domain to another address, keeping the path. Edge rules, not DNS — and nothing that costs a request.

Status: 308 by default · path kept · needs a proxied name

```javascript
await domain.redirects.add({ from: "www", to: "@" });
// { id, source: "www.example.com", target: "https://example.com",
//   status: 308, keepPath: true, keepQuery: true, recordCreated: true }

await domain.redirects.add({ from: "@", to: "https://elsewhere.com", status: 301, keepPath: false });

await domain.redirects.list();
await domain.redirects.remove(id);
```

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `from` | string | required | A name of the zone — `www`, or `@` for the root. |
| `to` | string | required | Another name of the zone, or an absolute **https** address. |
| `status` | number | 308 | 308 keeps the method; 301 is the older permanent; 302 and 307 are temporary. |
| `keepPath` | boolean | true | `/blog/x` arrives at `/blog/x`. False sends everything to the target root. |
| `keepQuery` | boolean | true | Keeps the query string as it was. |

## A CNAME does not redirect {#not-dns}

A DNS record points a name at a machine; it never tells a browser to go elsewhere, and it cannot keep the path. That is why this is not part of [records](/sdk/ref/domain/records/set).

## The name has to be seen by the edge {#proxied}

> **A name served directly is refused, not switched**
>
> A rule only applies to traffic the edge sees. With nothing on the name, the call poses what is needed and says so with `recordCreated`. With a record that bypasses the edge, it answers `redirect_source_not_proxied` rather than changing how your name is served behind your back.

## Removing {#removing}

`remove(id)` drops the rule, and the record it had posed if that record served nothing else — `recordRemoved` says whether it did.

- [attach()](/sdk/ref/domain/attach): Putting a host behind the name.
- [records](/sdk/ref/domain/records/list): The zone underneath.

```python
domain.redirects.add(from_name="www", to="@")
# {"id", "source": "www.example.com", "target": "https://example.com",
#  "status": 308, "keepPath": True, "keepQuery": True, "recordCreated": True}

domain.redirects.add(from_name="@", to="https://elsewhere.com", status=301, keep_path=False)

domain.redirects.list()
domain.redirects.remove(redirect_id)
```
