Report Tool or Give Us Suggestions

301 Redirect Code Generator

Generate permanent 301 redirect snippets for Apache, Nginx, PHP, HTML meta refresh, and JavaScript.

L ading . . .

301 Redirect Code Generator for Apache, Nginx, PHP, HTML, and JavaScript

HTTP 301 Moved Permanently tells browsers and search engines that a URL has a stable new location. This generator drafts ready-to-paste snippets for common stacks. Prefer server-driven 301 responses from Apache or Nginx whenever you control the host configuration; HTML meta refresh and JavaScript redirects are fallbacks when you cannot set headers.

Snippet types

  • Apache: simple Redirect directive plus an optional mod_rewrite style comment.
  • Nginx: return 301 inside a location block—adjust to match your server_name and paths.
  • PHP: sends Location with response code 301 and exits immediately.
  • HTML: meta refresh plus a visible link for accessibility.
  • JavaScript: window.location.replace to avoid keeping the old URL in history.

SEO and caching notes

Real 301 responses preserve ranking signals better than client-side redirects. After deploying, verify with curl or your browser devtools network panel that the status code is 301 and that only one hop reaches the final URL when possible.

Frequently Asked Questions

301 or 302?

Use 301 when the move is permanent. Use 302 or 307 for temporary campaigns or maintenance pages.

Can I redirect HTTP to HTTPS here?

Yes—put your https URL as the destination. You still need TLS certificates and virtual host configuration on the server.

Why avoid meta refresh for important pages?

Search engines treat it as weaker than an HTTP redirect, and users without meta support may not follow automatically.

Does this handle query strings?

The Nginx example comments show how you might append $request_uri for prefix moves. Tailor rules to your routing design.

logo OnlineMiniTools

OnlineMiniTools.com is your ultimate destination for a wide range of web-based tools, all available for free.

Feel free to reach out with any suggestions or improvements for any tool at admin@onlineminitools.com. We value your feedback and are continuously striving to enhance the tool's functionality.

© 2026 OnlineMiniTools . All rights reserved.

Hosted on Hostinger

v1.10.0