Redirect Generator for .htaccess, nginx and Cloudflare
Paste a list of old and new URLs and get redirect rules ready to drop into Apache, nginx or Cloudflare. Chains, loops and duplicates are caught before they reach your server.
Options
htaccess-redirects.txt
301 or 302
Use 301 when the move is permanent: a new URL structure, a merged page, a domain change. Use 302 when the old URL will come back, such as a seasonal page or a short test. Google has said that 3xx redirects do not lose PageRank, so the choice is about intent. With a 301 Google moves its signals to the new URL and shows the new URL in results. With a 302 it keeps showing the old one for longer.
307 and 308 are the strict versions of 302 and 301 that keep the request method, which matters for forms and APIs, not for normal pages. Google treats 308 like 301 and 307 like 302.
.htaccess: Redirect or RewriteRule
Apache has two ways to write a redirect, and they behave differently.
| Redirect (mod_alias) | RewriteRule (mod_rewrite) | |
|---|---|---|
| Matching | Prefix: /old also catches /old/page | Exact, with ^ and $ |
| Query string | Always passed on, cannot match it | Can match it with RewriteCond, keep it or drop it with QSD |
| Order | First match in the file | Runs before any Redirect line, whatever the file order |
This tool writes Redirect lines when every rule is a plain path and you keep the query string, sorted with the longest path first so a parent folder does not swallow its children. As soon as one old URL has a query string, you choose to drop the query string, or you add host rules, it switches the whole file to RewriteRule. Mixing the two modules in one file is the classic cause of redirects that work on one URL and not the next. On WordPress, put the rules above the # BEGIN WordPress block, because WordPress rewrites every request it does not recognise to index.php.
nginx: location blocks and a map
For a handful of redirects the output is location = /old { return 301 /new; } blocks, which go inside your server {} block. For more than five, a map is cleaner and faster: nginx looks the URL up in a hash table instead of checking each location. The map goes in the http {} block and the if ($redirect_uri) line goes in the server block.
The map uses $uri, which has the query string removed, and appends $is_args$args when you keep the query string. Old URLs that contain a query string get their own map on $request_uri. Run nginx -t before you reload: a duplicate key in a map makes nginx refuse the whole config, which is why this tool removes duplicates first.
Cloudflare Bulk Redirects
The Cloudflare output is the CSV that a Bulk Redirect List imports. The columns are source URL, target URL, status code, preserve query string, include subdomains, subpath matching and preserve path suffix. Cloudflare does not allow a header row, so the file has none. In the dashboard, create a Bulk Redirect List, import the CSV, then create a Bulk Redirect Rule that uses the list. The list does nothing until a rule turns it on.
Two limits to know: a source URL cannot contain a query string, so those rows are skipped and flagged, and the CSV cannot hold host rules. For https and www, turn on Always Use HTTPS and add a Single Redirect rule.
Chains and loops
A chain is A to B to C. It happens when you redirect a page that was already the target of an earlier redirect, which is normal after two or three site rebuilds. Googlebot follows up to 10 hops, but each hop is another request for every visitor and crawler, and link signals are cleaner when the old URL points straight at the final page. The Flatten chains button rewrites each old URL in your list to its final destination.
A loop is A to B and B back to A, or a URL that redirects to itself. Browsers stop with "too many redirects" and the page is unreachable. The most common source is a mapping rule that fights a trailing slash or www rule, which is why the generator compares URLs with the same normalisation your options use.
Redirect map checklist for a site migration
- Map every old URL that has traffic or backlinks to its closest new equivalent. Sending everything to the homepage is treated by Google as a soft 404.
- Use the same scheme and host as your canonical site in targets, so each old URL takes one hop.
- Update internal links and the XML sitemap to the new URLs. Redirects are for the outside world, not your own menus.
- Keep the redirects for at least a year. Google's site move guidance asks for that, and links from other sites stay much longer.
- After launch, crawl the old URL list and check that every one returns a single 301 to a 200 page.