301 Redirect Code Generator
Enter the old URL and the new destination, pick your redirect type and server platform, and get the ready-to-paste redirect code.
Last updated: May 26, 2026
Find this tool useful? Support the project to keep it free!
Buy me a coffeeWhat is 301 Redirect Code Generator?
A redirect tells browsers and search engines that a URL has moved. The HTTP status code signals whether the move is permanent (301, 308) or temporary (302, 307), and search engines transfer link equity accordingly.
The implementation differs by platform: Apache uses the `Redirect` directive in `.htaccess`, Nginx uses `return` or `rewrite`, IIS uses a `<rewrite>` rule in `web.config`, PHP uses `header('Location: ...')`, and client-side redirects use the meta refresh tag or JavaScript. This tool generates the correct snippet for each platform.
How to Use 301 Redirect Code Generator
Enter the old path (e.g. /old-page) in "From URL".
Enter the full new URL in "To URL".
Choose the redirect type (301 for permanent SEO-friendly moves).
Choose the server/platform you're using.
Copy the generated code and paste it into the appropriate config file.
Common Use Cases
- Redirecting old blog post URLs after a site redesign.
- Setting up 301 redirects when migrating to a new domain.
- Creating temporary 302 redirects for A/B testing.
- Generating server-specific redirect syntax without memorizing the format.
- Building redirect rules for Apache, Nginx, or IIS configurations.
Example Input and Output
A permanent 301 redirect from /old-page to /new-page in Apache .htaccess.
From: /old-page → To: https://example.com/new-page (301, Apache)# Add to your .htaccess file
Redirect 301 /old-page https://example.com/new-pagePrivacy
All code generation happens in your browser. No URLs are sent to a server.
Nginx rewrite vs return
The generated Nginx code shows both a location block with return and an equivalent rewrite. The return directive is simpler and recommended; the rewrite is shown as an alternative if you already have a rewrite context.
Frequently Asked Questions
What is the difference between 301 and 302?
A 301 is permanent — search engines update their index and transfer link equity to the new URL. A 302 is temporary — search engines keep the old URL in their index.
Which redirect type should I use for an SEO migration?
Use 301 for any permanent URL move. It signals to search engines that the new URL is canonical and transfers ranking signals from the old URL.
Does HTML meta refresh affect SEO?
Meta refresh is not a true HTTP redirect. It has delays and is less reliable for SEO. Use server-side redirects whenever possible.
Does this send my URLs anywhere?
No. All code generation happens in your browser.
Related Tools
HTML Beautifier
Format and beautify minified or messy HTML code.
HTML Minifier
Compress HTML by removing whitespace, comments, and redundant attributes — with size reduction stats.
Hyperlink Generator
Generate HTML anchor (<a>) tags with full control over href, link text, target, rel, title, class, id, style, and download attributes. Live preview included.
HTML Compressor
Compress and minify HTML by removing comments, collapsing whitespace, stripping empty attributes, and removing optional tags. Shows byte savings.
Meta Tag Generator
Generate SEO title tags, meta descriptions, Open Graph, and Twitter Card tags for any webpage.
Code Highlighter
Paste code in JavaScript, TypeScript, Python, HTML, CSS, SQL, JSON, or Bash and get a syntax-highlighted HTML snippet you can embed anywhere. Live preview and copy-ready output.

