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
Find this tool useful? Support the project to keep it free!
Buy me a coffeeWhat 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
Enter the old path (e.g. /old-page) in the "From" field
Enter the full destination URL (e.g. https://example.com/new-page) in the "To" field
Choose 301 (permanent) or 302 (temporary)
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.
From: /old-blog/post-1
To: https://example.com/blog/post-1
Type: 301 PermanentRedirect 301 /old-blog/post-1 https://example.com/blog/post-1Privacy
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.

