.htaccess Redirect Builder

Convert a list of old → new URLs into Apache 301 redirect rules.

Open tool

Overview

The .htaccess Redirect Builder turns a plain list of old URL → new URL pairs into a syntactically correct block of Apache Redirect 301 or RewriteRule directives that you can paste straight into an .htaccess file or virtual host config. It removes the boilerplate of escaping query strings, picking permanent vs temporary status codes, and matching the right module for the job.

Reach for this when migrating a site to a new URL scheme, consolidating duplicate paths after an information-architecture rewrite, or recovering link equity after a domain change. It is most useful for SEO practitioners and webmasters who need bulk 301 redirects on Apache or LiteSpeed without writing regex by hand and want to know how to write 301 redirects in htaccess correctly the first time.

How it works

Apache's mod_alias provides the simple Redirect and RedirectMatch directives, while mod_rewrite gives you the more flexible RewriteRule with [R=301,L] flags. The builder reads each input pair, detects whether a query string or pattern is present, and emits the cleaner directive — Redirect 301 /old /new for static paths and RewriteRule for anything containing regex metacharacters or query parameters.

Output is grouped, deduplicated, and sorted so longest paths come first — important because Apache evaluates .htaccess directives in order and a /blog rule placed before /blog/post-1 would swallow the more specific match.

Examples

  • /about-us → /about becomes Redirect 301 /about-us /about.
  • /old-shop/* → /shop/* becomes a RewriteRule ^old-shop/(.*)$ /shop/$1 [R=301,L].
  • /page?id=42 → /article/hello-world emits a RewriteCond %{QUERY_STRING} block plus a RewriteRule.
  • Pasting 30 legacy URLs at once yields a single block with one rule per line, ready to drop into .htaccess.

FAQ

Should I use 301 or 302?

301 is permanent and passes link equity, which is what you want for migrations. Use 302 only for temporary redirects you plan to remove within weeks.

Do these rules work on Nginx?

No. Nginx uses its own rewrite and return 301 syntax in server blocks. The output here targets Apache and Apache-compatible servers like LiteSpeed.

Why does order matter?

Apache walks the file top-to-bottom and stops at the first match with [L]. Specific paths must appear before broad patterns or they will never be reached.

Can I redirect across hosts?

Yes. Provide an absolute URL on the right-hand side and the builder emits an R=301 rule with the full destination, suitable for moving content to a different domain.

Try .htaccess Redirect Builder

An unhandled error has occurred. Reload ×