2020-01-24 12:47:52 -07:00
---
title: redir (Caddyfile directive)
---
# redir
Issues an HTTP redirect to the client.
2023-01-28 05:16:21 +01:00
This directive implies that a matched request is to be rejected. It is ordered very early in the [handler chain ](/docs/caddyfile/directives#directive-order ) (before [`rewrite` ](/docs/caddyfile/directives/rewrite )).
2020-01-24 12:47:52 -07:00
## Syntax
2020-05-17 16:32:12 -04:00
```caddy-d
2020-01-24 12:47:52 -07:00
redir [< matcher > ] < to > [< code > ]
```
- **< to> ** is the target location. Becomes the response's Location header.
- **< code> ** is the HTTP status code to use for the redirect. Can be:
2022-05-17 14:32:11 -04:00
- A positive integer in the 3xx range, or 401
2020-01-24 12:47:52 -07:00
- `temporary` for a temporary redirect (302; default)
- `permanent` for a permanent redirect (301)
- `html` to use an HTML document to perform the redirect (useful for redirecting browsers but not API clients)
2022-05-17 14:32:11 -04:00
- A placeholder with a status code value
2020-01-24 12:47:52 -07:00
## Examples
Redirect all requests to `https://example.com` :
2020-05-17 16:32:12 -04:00
```caddy-d
2020-01-24 12:47:52 -07:00
redir https://example.com
```
Same, but preserve the existing URI:
2020-05-17 16:32:12 -04:00
```caddy-d
2020-01-24 12:47:52 -07:00
redir https://example.com{uri}
```
Same, but permanent:
2020-05-17 16:32:12 -04:00
```caddy-d
2020-01-24 12:47:52 -07:00
redir https://example.com{uri} permanent
2022-05-17 14:32:11 -04:00
```
Redirect your old `/about-us` page to your new `/about` page:
```caddy-d
redir /about-us /about
```