Formatters & Code

htaccess Redirect Generator

Generate an Apache redirect rule for a single path.

Results appear here.

What the result means

The result is one Apache Redirect directive. The status you picked, 301 or 302, is written first, then the path, then the absolute target. A 301 says the move is permanent, so clients may remember the new address. A 302 says the move is temporary, so caches should not treat the target as the lasting home of that path. The path has to begin with a slash. The target has to begin with http or https, which keeps other schemes out of the snippet. These lines do nothing on Nginx, and they are not how Cloudflare expects a redirect to be configured. On Cloudflare, use a Redirect Rule. On Nginx, use a return or rewrite in the server configuration. This page only prints the line. It does not install it.

Related tools

Advertisement

Questions

301 or 302?

Use 301 when the path has moved for good and clients may remember the new URL. Use 302 when the change is temporary and the old path may come back.

Will this work on Cloudflare?

No. This is Apache. On Cloudflare use a Redirect Rule instead. Nginx does not read this directive either.

Why must the target be http or https?

So the snippet cannot point at a javascript or data URL. The path must also start with a slash, because the directive matches a URL path on the server.