Format Code Now
/
Web & markup301 Redirect Generator Next: HTML to JSX Converter ›

301 Redirect Generator

WM-21

Write one old path and one new path per line to get 301 redirect rules for Apache .htaccess, Nginx, Netlify or Cloudflare Pages. Duplicates, loops and bad paths are caught.

Runs in your browser. Nothing is uploaded.

Redirects, one "old new" pair per line

Rules

How to use it

  1. Write one redirect per line: the old path, a space, then the new path or a full address.
  2. Pick the format and the status code. 301 is permanent, 302 is temporary.
  3. Choose Generate and read any warning lines at the top.
  4. Copy the rules into .htaccess, your Nginx server block, or a _redirects file.

Which format does what

Apache Redirect writes Redirect 301 /old /new lines for .htaccess. It matches the path and everything below it, so /old also catches /old/page. The RewriteRule option matches the exact path only. Nginx output is one location = /old block per line, to place inside a server block; /old and /old/ are different paths there. Netlify and Cloudflare Pages both use the _redirects format, one /old /new 301 line per rule.

What is checked

The old address must be a path that starts with /, with no ? or #, because redirect rules match the path and ignore the query string and fragment. The new address must be a path or a full http or https address. Duplicate old paths, a path that redirects to itself and characters that could break a rule, such as quotes, spaces or a dollar sign, are refused with the line number. Apache and Nginx match the decoded path, so %20 in the old path is written as a real space, in quotes or as a backslash and space in a RewriteRule. Wildcards are accepted only for Netlify and Cloudflare Pages.

Chains, loops and testing

If one rule sends visitors to a path that another rule redirects again, a warning comment shows the chain and the final target, so you can point the first rule straight at it. Two rules that send visitors back and forth are flagged as a loop. The tool writes the text only. It does not test the rules against a live server, so try a few old addresses after you deploy, and keep a copy of your old config.

Error messages and what to do

MessageWhat it meansFix
Line 2: expected two values, "old new", but found 3.A line has too many or too few parts.Write the old path and the new address separated by one space.
Line 1: the old address must be a path starting with /, such as /old-page.The old value is a full address or has no leading slash.Use only the path part, starting with /.
Line 4: /old is already redirected on line 2.The same old path appears twice.Remove one of the lines.
No redirect lines found. Write one per line as: /old-path /new-pathThe input has only blank lines and comments.Add at least one redirect line.

Questions people ask

How do I write the input?

One redirect per line: /old-page /new-page. You can use -> between them. Lines starting with # are comments and are ignored. The new address can be a full URL such as https://example.com/page.

What is the difference between 301 and 302?

A 301 tells browsers and search engines the move is permanent, so they update their records. A 302 says it is temporary. 307 and 308 behave like 302 and 301 but keep the request method, which matters for form posts.

Where does the .htaccess file go?

In the folder that holds the site, on an Apache server that allows overrides. Copy the lines into the file, keeping any existing content. If your host uses Nginx instead, choose the Nginx format.

Can I redirect a whole folder with a wildcard?

For Netlify and Cloudflare Pages, yes: write the old path with * at the end and use :splat in the new path. Wildcards are refused for the other formats, because Apache Redirect already matches everything below a path and Nginx needs a different rule type.

Why was my old URL with a query string refused?

Redirect rules match only the path. A ?id=5 in the old address would never match in these formats, so the tool asks you to remove it. Matching a query string needs a condition rule, which this tool does not write.

Will redirects keep my search rankings?

A permanent redirect from an old address to its closest replacement is the standard way to pass a page's signals to the new address. Results vary and take time, and redirecting many pages to one unrelated page is usually treated as a soft 404.

About this tool

Each line is an old path and a new path or full address, separated by a space or ->. Lines starting with # are ignored. The old address must be a path starting with /, without ? or #, because redirect rules match the path only. Apache Redirect matches that path and everything below it; RewriteRule and Nginx match the exact path, so /old and /old/ are different. Apache and Nginx match the decoded path, so %20 is written as a real space, quoted (and as a backslash and space in a RewriteRule). Wildcards (*) are accepted only for Netlify and Cloudflare Pages. The tool rejects duplicates, a path that redirects to itself and characters that could break a rule, and warns about chains and loops. It writes the rules; it does not test them on your server, and Nginx rules go inside a server block.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.