301 Redirect Code Generator

Enter the old address and the new one, choose the redirect type and what should move, then pick your server. You get the exact file to save, written in that server's own syntax.

Free Runs in your browser Checked Tuesday, November 10, 2026

A path such as /old-page/, or a full address such as https://old.example.com/old-page/. The server matches the path only.

The full address visitors should reach, starting with https:// or http://.

301 and 308 mean the move is permanent. 302 and 307 mean it is temporary.

Result

Cloudflare rule — The fields to fill in on the dashboard. This tool does not use the Cloudflare API.
Apache: .htaccess
nginx configuration
IIS: web.config
Caddyfile
Netlify: _redirects
HTML redirect page

This tool runs in your browser. What you enter is not sent to us.

How to use it

  1. Type the old address or path in Old address or path, for example /old-page/.
  2. Type the new address in New address, then choose the Redirect type and What to redirect.
  3. Choose the Server or platform. The code appears in the result, with a Copy and a Download button.
  4. Save the file on your server, then check each redirect with a request tool before you rely on it.

How the rule matches

A path rule matches the path you enter and sends the visitor to the new address. The page rule matches that one page, with or without its trailing slash. The folder rule matches the folder and every address below it, and carries the rest of the path to the new folder.

A host rule matches the host name of the old address. A domain rule carries the path and the query string to the same path on the new domain. The http to https rule matches requests that arrive over http, and the two www rules match one host name each.

  • The server rules keep the query string, so /old-page/?ref=1 becomes /new-page/?ref=1.
  • A regular expression is generated from the path: its dots, brackets and other special characters are escaped, so the rule matches the text you typed.

Which status code to choose

Google's redirect guide says: "The 301 and 308 status codes mean that a page has permanently moved to a new location." It lists 302 and 307 under temporary redirects, and it names moving a site to a new domain as a typical case: "You've moved your site to a new domain, and you want to make the transition as seamless as possible." It adds: "Use permanent redirects when you're sure that the redirect won't be reverted."

A permanent redirect tells search engines to show the new address in their results. A temporary redirect keeps the old address in the results, which is right only when the old page is expected to return.

Differences between servers

Each server writes redirects differently, and some do not accept every code. This tool writes the nearest code each server supports and says so in the result.

  • IIS URL Rewrite supports 301, 302, 303 and 307 and not 308, so a 308 choice becomes 301 there.
  • Netlify documents 302 in place of 307 and does not list 308, so 307 becomes 302 and 308 becomes 301.
  • Apache mod_alias Redirect matches a prefix, while a mod_rewrite RewriteRule matches the exact path that you give.
  • A Cloudflare Single Redirect is a dashboard rule. This tool shows its fields; it does not create the rule.

Meta refresh and JavaScript: the last resort

Google's guide orders the redirect types by how likely Google is to interpret them correctly: server-side redirects first, then meta refresh, then JavaScript. Google says an instant meta refresh (0 seconds) is interpreted as a permanent redirect and a delayed one as a temporary redirect.

Google's guide also says: "Only use JavaScript redirects if you can't do server-side or meta refresh redirects." It adds that rendering may fail, so Google might never see a JavaScript redirect. The HTML output of this tool uses a 0-second meta refresh for 301 and 308, and a 5-second one for 302 and 307.

Worked example: one page moved with a 301

Enter /old-page/ as the old address, https://example.com/new-page/ as the new address, 301 as the redirect type and One page as the scope. The Apache result is the RewriteRule line below, and every other server gets its own file with the same target.

The rule matches the exact page, with or without the trailing slash, and the server rules keep the query string. The Cloudflare fields are the expression and the static target, with the status code 301.

Server File Line that makes the redirect
Apache .htaccess RewriteRule ^old-page/?$ https://example.com/new-page/ [R=301,L,QSA]
nginx nginx-redirect.conf return 301 "https://example.com/new-page/$is_args$args";
Caddy Caddyfile redir @page "https://example.com/new-page/{?query}" 301
Netlify _redirects /old-page https://example.com/new-page/ 301
Cloudflare dashboard fields Custom filter expression: (http.request.uri.path eq "/old-page" or http.request.uri.path eq "/old-page/")
HTML page redirect.html meta refresh attribute content="0; url=https://example.com/new-page/"

Frequently asked questions

Should I use 301 or 302?

Use 301 when the old page has moved for good, so search engines show the new address. Use 302 only when the move is temporary, for example during maintenance.

Is 308 the same as 301?

Both mean that the page has permanently moved. A 308 keeps the request method, so a POST stays a POST, while a 301 may turn it into a GET. IIS URL Rewrite does not support 308, so this tool writes 301 for IIS.

Why does the Apache Redirect line cover more than the RewriteRule?

The Redirect directive is a prefix match: it also sends /old-page/anything to the new address. The RewriteRule matches the exact page only, which is why it is the active line in the output.

Does this tool send anything to my server or to Cloudflare?

No. The code is written in your browser and nothing you enter leaves the page. A Cloudflare rule has to be created in the dashboard by hand, so the tool lists its fields instead.

Why is a meta refresh only the last resort?

Google's guide ranks the methods: server-side redirects come first, then meta refresh, and JavaScript last. A page file also sends visitors to a single address, so a folder or a whole domain needs a server rule.

Why does a 307 choice become a 302 for Netlify?

Netlify's redirect options say to use 302 instead of 307, which it does not support. The file carries a comment that says so.

Sources

Figures and text last checked on Tuesday, November 10, 2026.

We use necessary cookies to run the site. With your consent, Google also uses advertising cookies to show personalised ads. If you reject them, you still see ads, but they are not personalised.