WebToolsPlanet
Developer Tools

301 Redirect Code Generator

Enter an old URL path and a new destination URL, choose 301 (permanent) or 302 (temporary), and get ready-to-use redirect code for six server environments.

Last updated: May 21, 2026

Client-Side Processing
Input Data Stays on Device
Instant Local Execution

Find this tool useful? Support the project to keep it free!

Buy me a coffee

What is 301 Redirect Code Generator?

HTTP redirects tell browsers and search engines that a URL has moved. A **301 redirect** is permanent — search engines transfer link equity to the new URL and update their index. A **302 redirect** is temporary — search engines keep the original URL indexed and do not transfer ranking signals.

Implementing a redirect depends on your server or framework. Apache uses `.htaccess` directives, Nginx uses `rewrite` rules in the site config, PHP uses the `header()` function, and Node.js/Express uses `res.redirect()`. This tool generates the correct snippet for all six environments from a single form.

How to Use 301 Redirect Code Generator

1

Enter the old path (e.g. /old-page) in the "From" field

2

Enter the full destination URL (e.g. https://example.com/new-page) in the "To" field

3

Choose 301 (permanent) or 302 (temporary)

4

Copy the snippet for your server environment

Common Use Cases

  • Developers redirecting old blog post URLs to new ones after a site redesign.
  • Site owners redirecting HTTP to HTTPS or www to non-www.
  • Teams migrating from one domain to another with proper 301 redirects for SEO.
  • Developers setting up temporary redirects during maintenance or A/B testing.
  • Front-end engineers implementing client-side redirects via JavaScript or HTML meta.
  • DevOps engineers configuring server-level redirects in Apache or Nginx configs.

Example Input and Output

Redirect /old-blog/post-1 to the new URL with a 301 permanent redirect.

Redirect configuration
From: /old-blog/post-1
To: https://example.com/blog/post-1
Type: 301 Permanent
Apache .htaccess snippet
Redirect 301 /old-blog/post-1 https://example.com/blog/post-1

Privacy

All code generation runs in your browser. No URLs or data are sent to any server.

Tip: test redirects before deploying

Use browser DevTools (Network tab) or curl -I to verify that a redirect returns the correct status code (301 or 302) before deploying to production.

Frequently Asked Questions

When should I use 301 vs 302?
Use 301 for permanent moves (domain migration, URL restructuring, HTTP to HTTPS). Use 302 for temporary redirects (maintenance pages, A/B tests, seasonal content). Search engines pass link equity for 301 but not 302.
Does the HTML meta redirect affect SEO?
HTML meta refresh is not a true HTTP redirect — it runs in the browser, not the server. Search engines may follow it but it does not reliably transfer link equity. Use server-side redirects (Apache, Nginx, PHP) for SEO-critical redirects.
What is the difference between Apache Redirect and RewriteRule?
The Redirect directive is simpler and sufficient for most cases. RewriteRule (via mod_rewrite) is more powerful and supports patterns, conditions, and complex rules. This generator uses the simpler Redirect directive.