# Redirect rules generator

Turn a list of old and new addresses into redirect rules for Apache .htaccess, Nginx, or a Netlify _redirects file.

- Endpoint: `POST https://setget.net/v1/tools/htaccess-redirects` with JSON `{"input": {...}}`
- MCP: `run_tool` with `slug` = `htaccess-redirects`
- Page: https://setget.net/tools/htaccess-redirects

## Inputs

- `redirects` (required, json): The redirects: a list of {"from": "/old", "to": "/new"} objects or ["/old", "/new"] pairs. Plain text with "old new" on each line also works.
- `format` (optional, string, one of `apache`, `nginx`, `netlify`, default `"apache"`): Which server the rules are for. netlify is the _redirects format, also used by Cloudflare Pages.
- `status` (optional, integer, one of `301`, `302`, default `301`): 301 for a permanent move (best for SEO), 302 for a temporary one.

## Example 1

```json
{"input":{"redirects":[{"from":"/old-page","to":"/new-page"},["/blog/2019/post.html","https://blog.example.com/post"]]}}
```

Result:

```json
{"text":"RedirectMatch 301 ^/old-page$ /new-page\nRedirectMatch 301 ^/blog/2019/post\\.html$ https://blog.example.com/post\n","count":2,"filename":".htaccess"}
```

## Example 2: Nginx, from plain text

```json
{"input":{"redirects":"/old-page /new-page\n/sale /offers","format":"nginx","status":302}}
```

Result:

```json
{"text":"location = /old-page { return 302 /new-page; }\nlocation = /sale { return 302 /offers; }\n","count":2,"filename":"redirects.conf"}
```

## Example 3: Netlify and Cloudflare Pages

```json
{"input":{"redirects":[["/old-page","/new-page"]],"format":"netlify"}}
```

Result:

```json
{"text":"/old-page /new-page 301\n","count":1,"filename":"_redirects"}
```

**Where do the rules go?** Apache: in the .htaccess file at the site root. Nginx: inside the server { } block. Netlify and Cloudflare Pages: in a file named _redirects in the published folder.

**Do the rules match the exact address?** Yes. Each rule matches that one path, not everything beneath it. Query strings (the part after ?) are not part of the match.

**301 or 302?** Use 301 when the move is permanent so search engines transfer ranking to the new address. Use 302 for short-term moves.
