WebToolsPlanet
Developer Tools

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

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?

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

1

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

2

Enter the full new URL in "To URL".

3

Choose the redirect type (301 for permanent SEO-friendly moves).

4

Choose the server/platform you're using.

5

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.

Configuration
From: /old-page → To: https://example.com/new-page (301, Apache)
Generated .htaccess code
# Add to your .htaccess file
Redirect 301 /old-page https://example.com/new-page

Privacy

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.