b2KIT

.htaccess Redirect Generator

Generate Apache .htaccess redirect rules for 301, 302, and rewrite configurations.

How to Use .htaccess Redirect Generator

  1. 1

    Enter the old URL

    Type the source URL path you want to redirect from.

  2. 2

    Enter the new URL

    Type the destination URL path to redirect to.

  3. 3

    Select redirect type

    Choose 301 permanent or 302 temporary redirect.

  4. 4

    Copy the rule

    Click copy to grab the .htaccess redirect rule.

Tested tool guide Tested browser tools Checked August 16, 2026

What .htaccess Redirect Generator does, with a checked example

Takes an old URL path, a destination URL, and a status code, and returns ready-to-paste Apache directives: a mod_alias Redirect line, a mod_rewrite RewriteRule block, or both. It handles the syntax details that routinely break hand-written rules: RewriteEngine On, the [R=301,L] flag pair, and the pattern rules that differ between the two modules. The usual surprise is that Redirect and RewriteRule are not interchangeable: Redirect matches a path prefix and keeps the query string, while RewriteRule matches a regex against the path alone, and the two treat trailing slashes differently.

Worked example

A concrete input and expected output from the current implementation.

Input

Old path: /old-page
Destination: https://example.com/new-page
Status: 301

Expected output

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

RewriteEngine On
RewriteRule ^old-page/?$ https://example.com/new-page [R=301,L]

Both lines are valid Apache syntax for the same move: the Redirect form matches /old-page and everything beneath it, while the RewriteRule matches exactly /old-page with an optional trailing slash. Same status code, two different match scopes.

How the result is produced

1

Two modules, one file

Apache ships two independent redirect systems, and this tool emits whichever you ask for. mod_alias provides Redirect and RedirectMatch: plain prefix rules that need no extra setup. mod_rewrite provides RewriteEngine and RewriteRule: regex rules that are ignored entirely unless RewriteEngine On is enabled earlier in the file, which is why the generated rewrite block leads with that line. The two systems coexist but evaluate independently.

2

What the pattern actually matches

With Redirect, the old path is a prefix: Redirect 301 /old catches /old, /old/ and /old/anything, and appends the remainder to the destination. With RewriteRule in .htaccess, Apache strips the leading slash and the pattern is a regex, so ^old-page/?$ catches only those two strings. Neither form matches against the query string: Redirect keeps it, RewriteRule appends it unless the destination contains a question mark.

Good uses

  • Rebuilding a site's URL structure: after a redesign, every old article or product URL gets a 301 to its new location so bookmarks, links, and search rankings follow the content.
  • Switching domains: when a site moves to a new host or domain, generate permanent redirects from every old-address URL to the matching new one so visitors and crawlers land on the right page.
  • Temporary swaps that must not stick: a seasonal landing page or a maintenance hold that should return to its original URL later, where a 302 tells search engines this is a temporary move.

Limits and checks

  • Prefix matching overreaches: Redirect 301 /old redirects /old and every path beneath it, not just the exact page. If only one URL should move, a plain Redirect is too broad; use the RewriteRule form with an anchored pattern, which matches only the exact path plus the trailing-slash variant.
  • Query strings diverge between the forms: Redirect carries the query string over automatically. RewriteRule carries it only when the destination URL contains no question mark of its own; a destination such as https://example.com/new? replaces the original query, and you would need [QSA] to append it instead.
  • The file may never be read: .htaccess directives do nothing when the host runs Apache with AllowOverride disabled, and every mod_rewrite rule is ignored without RewriteEngine On. A rule can look correct and never fire; verify each one with curl -I and check the returned status and Location header.

Common questions

Will my redirects keep the URL parameters such as ?id=42 or ?utm_source=newsletter?

Redirect keeps them automatically. RewriteRule keeps them as long as the destination URL contains no question mark; if the destination has a query string of its own, the original is discarded unless you add [QSA]. So: yes for Redirect, and for RewriteRule only when the destination has no ? of its own.

Does a 301 risk my search rankings if I move a page?

A correctly mapped 301 is the standard signal that a URL has permanently moved and its ranking signals should transfer to the destination. The risk is in the mapping: a redirect loop, or several old URLs pointing at one destination, can merge or lose those signals. Test each rule with curl -I before launch and remove stale rules when the move is complete.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools