Format Code Now
/
Web & markup301 Redirect Code Generator Next: Share Link Generator ›

301 Redirect Code Generator

WM-85

Enter the new address and pick a language. You get the code that redirects visitors there, with a permanent 301 status where the language can send one.

Runs in your browser. Nothing is uploaded.

Destination address (for .htaccess you can also give "old new" path pairs, one per line)

Redirect code

How to use it

  1. Type or paste the destination address, such as https://www.example.com/new-page/.
  2. Pick the language: .htaccess, PHP, HTML, JavaScript, Classic ASP or ASP.NET.
  3. Keep 301 for a permanent move, or choose 302, 307 or 308 for other cases.
  4. Copy the code into the old page or your server configuration.

Which options send a real 301

A 301 is an HTTP status, so only code that runs on the server can send it: PHP (header with 301), ASP and ASP.NET (Response status), and Apache .htaccess rules. HTML meta refresh and JavaScript run in the browser after the page has loaded and always arrive as a normal 200 page, so search engines do not read them as a permanent move. The HTML page adds a canonical link as a hint, and the status choice does not change it.

Details worth knowing

For .htaccess, a single address uses RedirectMatch so every URL on the site goes to that address; pointing it at the same site would loop. To redirect individual pages, write old and new path pairs, one per line, and the tool writes a Redirect rule for each. Addresses with spaces, quotes, angle brackets or backslashes are refused, because they could break the generated code; percent-encode them instead. Test the redirect on your own server before relying on it.

Error messages and what to do

MessageWhat it meansFix
The destination must be a full address starting with http:// or https://, or a path starting with a single /.The address does not start with http://, https:// or /.Add https:// in front of the host name.

Questions people ask

How do I write a 301 redirect in PHP?

Send header('Location: https://example.com/new', true, 301) and then exit before any output. Choose PHP here to get exactly that code with your address. Place it before any output, because headers cannot be sent after the page has begun.

How do I do a 301 redirect in .htaccess?

Add a Redirect 301 /old-path /new-path line, or RedirectMatch for a pattern. For a list of old and new paths, choose .htaccess and write one pair per line.

Does a JavaScript or meta refresh redirect pass SEO value?

They are not a true 301, because no status code is sent. Search engines may follow them, but a server side 301 is the clear signal for a permanent move.

What is the difference between 301 and 302?

301 says the move is permanent, 302 says it is temporary. 307 and 308 are the temporary and permanent versions that also keep the request method, which matters for POST requests.

How do I redirect in ASP.NET?

Response.RedirectPermanent("url") sends a 301 in ASP.NET. For the other status codes the tool writes the status code and the Location header yourself, so the result still matches your choice.

Why was my address rejected?

Addresses must start with http://, https:// or a single /, and cannot hold spaces, quotes, angle brackets or backslashes. Percent-encode those characters first. An address with a space, for example, would break the quoted string in the code, so it is refused.

About this tool

Writes the code that sends visitors from one page to a new address. PHP, ASP, ASP.NET and .htaccess set a real HTTP status code (301 by default), which is what tells search engines the move is permanent. HTML meta refresh and JavaScript cannot send a status code, so they are not a true 301; the HTML page adds a canonical link as a hint, and the status choice does not change them. For .htaccess, a single destination uses RedirectMatch to send every URL on the site to it, so do not point it at the same site; old and new path pairs use the Redirect rules of the 301 Redirect Generator. The address must not contain spaces, quotes, angle brackets or backslashes; percent-encode them. The code is not tested on your server.

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