Redirect rules generator

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

Input

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

Result

Fill in the input and press Run.

Your input is processed in memory and then discarded. It is not stored or logged. Even so, don't paste live passwords or keys into any online tool.

Use it from code or an agent

curl -s https://setget.net/v1/tools/htaccess-redirects \
  -H 'Content-Type: application/json' \
  -d '{"input":{"redirects":[{"from":"/old-page","to":"/new-page"},["/blog/2019/post.html","https://blog.example.com/post"]]}}'
import json, urllib.request

body = {'input': {'redirects': [{'from': '/old-page', 'to': '/new-page'}, ['/blog/2019/post.html', 'https://blog.example.com/post']]}}
request = urllib.request.Request("https://setget.net/v1/tools/htaccess-redirects", json.dumps(body).encode(),
                                 {"Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(request))["result"])
const response = await fetch("https://setget.net/v1/tools/htaccess-redirects", {
  method: "POST",
  headers: {"Content-Type": "application/json"},
  body: JSON.stringify({"input":{"redirects":[{"from":"/old-page","to":"/new-page"},["/blog/2019/post.html","https://blog.example.com/post"]]}}),
});
console.log((await response.json()).result);
Tool: run_tool
Arguments:
{
  "slug": "htaccess-redirects",
  "input": {
    "redirects": [
      {
        "from": "/old-page",
        "to": "/new-page"
      },
      [
        "/blog/2019/post.html",
        "https://blog.example.com/post"
      ]
    ]
  }
}
{
  "input": {
    "redirects": [
      {
        "from": "/old-page",
        "to": "/new-page"
      },
      [
        "/blog/2019/post.html",
        "https://blog.example.com/post"
      ]
    ]
  }
}

Endpoint: POST /v1/tools/htaccess-redirects. Over MCP: run_tool with slug: "htaccess-redirects". Machine-readable: input schema, Markdown. Connect an agent.

Inputs

NameTypeRequiredWhat it does
redirects json yes 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 string no Which server the rules are for. netlify is the _redirects format, also used by Cloudflare Pages. One of: apache, nginx, netlify. Default: "apache".
status integer no 301 for a permanent move (best for SEO), 302 for a temporary one. One of: 301, 302. Default: 301.

Examples

Input
{
  "redirects": [
    {
      "from": "/old-page",
      "to": "/new-page"
    },
    [
      "/blog/2019/post.html",
      "https://blog.example.com/post"
    ]
  ]
}
Result
{
  "text": "RedirectMatch 301 ^/old-page$ /new-page\nRedirectMatch 301 ^/blog/2019/post\\.html$ https://blog.example.com/post\n",
  "count": 2,
  "filename": ".htaccess"
}

Nginx, from plain text

Input
{
  "redirects": "/old-page /new-page\n/sale /offers",
  "format": "nginx",
  "status": 302
}
Result
{
  "text": "location = /old-page { return 302 /new-page; }\nlocation = /sale { return 302 /offers; }\n",
  "count": 2,
  "filename": "redirects.conf"
}

Netlify and Cloudflare Pages

Input
{
  "redirects": [
    [
      "/old-page",
      "/new-page"
    ]
  ],
  "format": "netlify"
}
Result
{
  "text": "/old-page /new-page 301\n",
  "count": 1,
  "filename": "_redirects"
}

Questions

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.