Htaccess Redirect Generator

Every time you migrate a blog, change your URL scheme or consolidate old pages, Apache’s .htaccess takes the brunt of the cleanup. This generator turns a simple source → target mapping into the correct RewriteRule directives with the right flags, ready to drop into the site’s .htaccess file.

How to generate redirect rules

  1. 1

    Pick the redirect type

    301 permanent for SEO-safe moves, 302 temporary for A/B tests and seasonal redirects.

  2. 2

    Enter source and target

    Exact paths or regex patterns: the old path becomes the RewriteRule pattern, the new URL becomes the redirect target.

  3. 3

    Check the flags

    Every rule gets the right flag, `[R=301,L]` or `[R=302,L]`, so the block works with mod_rewrite out of the box.

  4. 4

    Copy the directives

    The generated block goes inside the `<IfModule mod_rewrite.c>` section of .htaccess.

mod_rewrite vs mod_alias directives

Apache offers two modules for redirects. Pick based on the complexity of the rule.

Decision guide

Requirement Use Example
Exact old URL → exact new URL Redirect Redirect 301 /old /new
Wildcard prefix RedirectMatch RedirectMatch 301 ^/blog/(.*)$ /articles/$1
Query-string match RewriteRule See below
Force HTTPS RewriteRule RewriteCond %{HTTPS} off + rule
Conditional (browser, cookie) RewriteRule With RewriteCond

Example: force HTTPS with www

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Example: move /blog/post-123 to /articles/post-123

RewriteEngine On
RewriteRule ^blog/(.*)$ /articles/$1 [L,R=301]

Flags you will see

  • L, last, do not continue processing further rules.
  • R=301 or R=302, redirect with that status code.
  • NC, case-insensitive.
  • QSA, append original query string to the new URL.
  • NE, do not re-encode special characters in the target.

Common mistakes

  • Forgetting RewriteEngine On, without it no RewriteRule has any effect.
  • Using 302 by default, Google treats it as temporary, so the old URL keeps ranking.
  • Chained redirects (old → intermediate → final), always aim for a single hop; each extra hop loses link equity and adds latency.

Frequently Asked Questions

Use 301 for permanent moves: site migration, URL slug change, HTTPS upgrade. Use 302 only for temporary situations, like routing to a maintenance page or an A/B split. Search engines transfer ranking signals on 301, not reliably on 302.

The most common cause is forgetting the leading slash in the pattern. In RewriteRule, the pattern matches the path without the leading slash (e.g. ^blog/). In Redirect (mod_alias), the pattern does start with a slash (/blog). Do not mix the two conventions.

Yes, use RewriteCond %{QUERY_STRING} ^id=123$ before a RewriteRule. Plain Redirect does not read the query string; only RewriteRule can match on it.

Yes, on the next request, Apache re-reads .htaccess per request. No server restart needed. If nothing happens, check that AllowOverride All is set in the vhost for the directory.

Related Tools

Tool available in other languages