.htaccess redirect generator

Pick the redirect type and enter the path or domain to get rules ready to paste into your .htaccess file.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter redirect type, from (old path or old domain) and to (new url or new domain).
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

Page redirects use the mod_alias Redirect directive. The others use mod_rewrite: a RewriteCond on %{HTTPS} or %{HTTP_HOST}, then RewriteRule ^ to the new address with %{REQUEST_URI} and the L and R=301 flags.

Example

Inputs: Redirect type = Page to page 301 (permanent), From (old path or old domain) = /old-page.html, To (new URL or new domain) = https://example.com/new-page/. Result: .htaccess rules: Redirect 301 /old-page.html https://example.com/new-page/; What it does: A permanent redirect that passes search ranking to the new address..

/old-page.html
Redirect 301 /old-page.html https://example.com/new-page/

Limits and caveats

  • For Apache and LiteSpeed only; Nginx does not read .htaccess.
  • Redirect also forwards sub-paths, so /old/x goes to /new/x.
  • Behind a CDN or load balancer %{HTTPS} can stay off and cause a loop; check X-Forwarded-Proto there instead.

Questions about this tool

When do I use 301 and when 302?

Use 301 when content has moved for good, and 302 for a temporary move such as a promo or maintenance page.

Is the query string kept?

Yes. Apache passes the original query string along as long as the new URL has no question mark.

Where do these rules go?

In the .htaccess file in the site root, ideally near the top before other rules.