Redirect Rule Generator (.htaccess, nginx)
.htaccess, nginx, Caddy and Netlify rules.
Exact matches one path (with or without a trailing slash when that option is on). Prefix matches the path and everything under it, carrying the rest over: /blog/ → /articles/ sends /blog/a/b to /articles/a/b. Regex matches the path (starting with /) and can use $1, $2 in the new URL. 301 and 308 are permanent; 302 and 307 temporary, and 307/308 keep the request method.
Bulk import from CSV
Site-wide rules
Site-wide redirects use 301. Rules are written in this order: host and HTTPS, your redirects (exact paths, then prefixes from longest to shortest, then regular expressions as entered), then index.html and trailing slashes. Paths that look like files (a dot in the last segment) never get a slash added.
Output
About the Redirect Rule Generator
This tool writes redirect rules for Apache (.htaccess with mod_rewrite), nginx, Caddy, Netlify (_redirects) and Vercel (vercel.json) from one list. Each rule has an old path, a new URL or path, a status code (301, 302, 307 or 308) and a match type: exact for one path, prefix for a path and everything below it (the rest of the path is carried over), or regex with $1-style references in the new URL.
Site-wide options add the usual canonical redirects: force HTTPS, www to the bare domain or the reverse, adding or removing the trailing slash, and stripping index.html. The output escapes regex characters in exact paths, percent-encodes spaces, and keeps the visitor's query string unless the rule itself matches one. Rules are ordered so that specific ones come before broad ones: exact paths, then prefixes from longest to shortest, then regular expressions in the order you entered them.
When a platform can't express a rule (Netlify has no regular expressions, for example), the tool says so instead of writing something that would behave differently.
How to use it
- Enter your redirects, or paste CSV lines (
old,new,status) into Bulk import from CSV. - Choose the site-wide options, and enter your domain for host redirects.
- Pick your server's tab, copy or download the file, and read where it goes.
Examples
- Import a list of redirects: an exact rule, a prefix rule and a temporary redirect.
Common questions
301 or 308?
Both are permanent, and Google treats them the same way. 308 also keeps the request method, which matters for forms and APIs; for ordinary pages, 301 is the most widely supported.
Why do my redirects loop?
Usually a rule's target matches another rule, or a trailing-slash rule fights a server that adds the slash to directories. Test each redirect after deploying it.
Where does the query string go?
It's passed on to the new URL. A rule that matches a specific query string replaces it with the new URL's own.
Related tools
- Redirect Chain: test the live redirects and count the hops.
- Robots.txt Generator: write crawl rules for the new URLs.
- Indexability Checker: confirm the new pages can be indexed.