Skip to content

Redirect generator for .htaccess, nginx, Cloudflare and Next.js

Paste a list of old and new URLs, from a spreadsheet, a site move plan or a CMS export, and get the redirect rules for your server in the syntax its own documentation gives: an .htaccess block for Apache, location rules for nginx, a CSV for Cloudflare bulk redirects, or a redirects() block for Next.js. Before you copy anything, the tool finds loops, chains, duplicates and conflicts in the list.

Quick answer

A redirect sends visitors and search engines from an old URL to a new one with an HTTP status code. Use 301 (or 308) when the move is permanent, so Google shows the new URL in results, and 302 (or 307) when it is temporary. Point each old URL straight to its final address: chains slow pages down and loops break them.

Runs in your browser, nothing is uploaded

Based on Google Search Central: Redirects and Google Search (last updated 14 Apr 2026) · Page updated 23 October 2026

Editor: Abuzar, founder of NeedMyToolsHow we check facts

Old and new URLs, one redirect per line

Old URL, then new URL. Separators: space, tab, comma, semicolon, pipe or ->. Add 301, 302, 307 or 308 as a third value to set one line's code. Lines starting with # are skipped.

Options

Used to read full old URLs as paths, to spot URLs on other domains, and as the host in the Cloudflare CSV.

Use 301 for moves you will not undo; 302 keeps the old URL in search results.

Your redirect rules

Paste near the top of the .htaccess file in your site root, before other rewrite rules. Needs mod_rewrite (Apache 2.4 for QSD).

Checks (no errors)

Loops, chains, duplicates and conflicts in your list are shown here.

These checks cover the list itself. After you deploy the rules, open a few old URLs in a private window to confirm the code and target.

How to use the Redirect Generator

  1. Paste your list, one redirect per line: the old URL, then the new URL, separated by a space, tab, comma, arrow or pipe. A third value of 301, 302, 307 or 308 sets that line's code; a header row and lines starting with # are skipped.
  2. Type your domain, so full old URLs on your site are read as paths and the Cloudflare CSV gets a host, and choose 301 or 302 as the default.
  3. Choose whether the old query string should be passed on, and whether chains should be shortened to point straight at the final URL.
  4. Read the checks: loops and self-redirects are left out of the output, conflicts keep the first line, and chains are listed with their line numbers.
  5. Pick Apache, nginx, Cloudflare or Next.js, then copy or download the rules and test a few old URLs on a staging copy before going live.

301 or 302: what Google says

Google's page on redirects and Google Search, last updated on 14 April 2026 and read by us on 23 October 2026, groups the server-side codes in two: 301 and 308 are permanent and tell Google to show the new URL in results, while 302, 303 and 307 are temporary and keep the old URL there. Google recommends a permanent server-side redirect whenever you are sure the move will not be reverted. Its site-move guide, updated on 20 August 2026, adds three habits worth keeping: send each old URL directly to its final destination, because Googlebot follows at most 10 hops and long chains add delay; keep the number of hops low if you cannot avoid a chain, ideally no more than three; and keep the redirects for as long as possible, generally at least a year.

Apache .htaccess: mod_rewrite rules

For Apache the tool writes RewriteRule lines, as described in the Apache HTTP Server 2.4 mod_rewrite documentation. In an .htaccess file the pattern is matched against the decoded path without its leading slash, so /old-page becomes ^old-page$, anchored at both ends so /old-page-2 is not caught by accident; the simpler Redirect directive matches by prefix, which is why we do not use it. Each rule has R with your status code, L to stop there, and NE so the target, already percent-encoded, is not encoded twice. Old URLs with a query string get a RewriteCond on %{QUERY_STRING}, and QSD drops that query from the target. A literal $ or % in the target is written with a backslash, because mod_rewrite reads $1 and %1 as back-references. Put the block near the top of the .htaccess file, after RewriteEngine On.

nginx, Cloudflare bulk redirects and Next.js

For nginx the tool writes an exact-match location for each path, which the nginx documentation says is compared with the decoded, normalised URI, with return and your status code inside; when the query string should be kept, $is_args$args is added. nginx locations never see the query string, so old URLs with one are matched with an if block on $request_uri, the request exactly as the browser sent it, using the rewrite module's if and return. For Cloudflare the tool writes the bulk redirects CSV described in Cloudflare's documentation: no header row, the source as host and path without a scheme, then the target, the status code and the four TRUE or FALSE options. Cloudflare does not accept a query string in a source URL, so those lines are listed as skipped. For Next.js the tool writes a redirects() block for next.config with statusCode set to your code, because permanent: true would send 308; query conditions use has items, and special characters in a source are escaped as the Next.js docs require.

Loops, chains and conflicts in your list

Redirect lists grow over years and often contradict themselves. The tool reads every line, normalises the old and new addresses, and follows each target through the rest of the list. A self-redirect such as /contact to /contact, or a loop such as /team to /about-us and back, would trap visitors and crawlers, so those rules are left out of the output and named in the checks. A chain such as /a to /b to /c works but costs an extra hop; with the shorten option on, the tool points /a straight at /c and says which lines it changed. Two lines for the same old URL with different targets are a conflict: the first one is kept, because in nginx two identical exact locations stop the configuration from loading. Old URLs on another domain, a fragment after #, which browsers never send to the server, and a redirect of your home page are all flagged for a second look.

Frequently asked questions

Which redirect is better for SEO, 301 or 302?

Use 301 when a page has moved for good: Google treats it as permanent and shows the new URL in search results. Use 302 only for a temporary move, when you want the old URL to stay in results. 308 and 307 are the permanent and temporary codes that also keep the request method.

How do I write a 301 redirect in .htaccess?

With mod_rewrite: RewriteEngine On, then one line per page such as RewriteRule ^old-page$ /new-page [R=301,L,NE]. Paste your old and new URLs in this redirect generator and it writes the lines for the whole list, including old URLs with a query string.

What is a redirect chain, and why avoid it?

A chain is a redirect that leads to another redirect, such as /a to /b to /c. Each hop adds a round trip, and Google advises sending the old URL straight to the final page. The tool finds chains in your list and can rewrite them to point at the last URL.

Can I redirect old URLs that have a query string, like page.php?id=5?

Yes in Apache, nginx and Next.js: the tool matches the exact query with RewriteCond, $request_uri or has items. Cloudflare bulk redirects cannot match a query string in the source URL, so those lines are skipped in the CSV and listed in the checks.

Does this tool test my live redirects?

No. It only writes rules from the list you paste, in your browser, and checks the list itself for loops, chains and conflicts. After you deploy the rules, open a few old URLs in a private window, or use a redirect checker, to confirm each one returns the code and target you expect.

Related guides