Free · in your browser

.htaccess Redirect Generator

Build clean Apache 301 and 302 redirect rules from old paths to new URLs — copy-and-paste ready. Free, instant and private: your data never leaves your device.

Private by design — your paths and URLs are processed locally and never uploaded.

How to generate .htaccess redirect rules

  1. Enter the old path (e.g. /old-page) and the new URL (e.g. https://example.com/new-page) for each move. Click + Add row for more.
  2. Choose the redirect type — 301 permanent or 302 temporary — and the directive style (Redirect or RewriteRule).
  3. Click Generate rules, then Copy the output and paste it into the .htaccess file in your site root.

Why use a redirect generator?

When you rename pages, restructure a site, or move to a new domain, broken URLs cost you traffic and rankings. Apache redirects send both visitors and search engines to the right place, and a 301 passes most of the old page's link equity to the new one. Hand-writing .htaccess rules is error-prone — a single stray space, a missing scheme, or a misplaced regex anchor can take down an entire site with a 500 error. This generator produces correctly formatted, copy-ready Redirect and RewriteRule lines in seconds, normalising old paths and escaping regex characters for you, so your migrations stay clean and your SEO stays intact.

301 vs 302: which redirect should you use?

Choosing the right status code is the single most important decision when setting up a redirect. The wrong one can either strand your ranking signals on a dead URL or tell Google to keep indexing a page you meant to retire.

Aspect 301 Permanent 302 Temporary
MeaningPage has moved for goodMove is short-lived
Link equityPassed to new URLKept on original URL
Indexed URLDestination replaces sourceSource stays indexed
Browser cachingCached aggressivelyRe-checked each visit
Use it forRenames, domain moves, HTTP→HTTPSA/B tests, sales, maintenance pages

Common use cases

  • Site restructure: point old slugs like /blog/2019/my-post to their new home after changing your URL scheme.
  • HTTPS or www migration: consolidate http:// and non-www variants onto your canonical domain.
  • Retiring pages: redirect a discontinued product to the most relevant category instead of returning a 404.
  • Vanity links: map short, memorable paths such as /demo to a longer campaign URL.

Tips & gotchas

  • Back up first. Save your existing .htaccess before pasting — a syntax error can return a 500 across the whole directory.
  • Order matters. Apache evaluates rules top to bottom; place more specific paths above broader ones to avoid premature matches.
  • Avoid chains and loops. Never redirect A→B→C; point both A and B straight at C. A rule whose source equals its destination causes an infinite loop.
  • Mind mod_alias vs mod_rewrite. Do not mix a bare Redirect with overlapping RewriteRule directives, as they can fire twice and stack query strings.
  • Test before you trust. Verify each rule with curl -I https://yoursite.com/old-path and confirm the status line reads 301 or 302.

Frequently asked questions

Is this .htaccess redirect generator free and private?
Yes — it is 100% free with no sign-up, and completely private. Your paths and URLs are turned into Apache redirect rules entirely in your browser; nothing is ever uploaded to a server.
What is the difference between a 301 and a 302 redirect?
A 301 is a permanent redirect — it tells search engines the page has moved for good and passes ranking signals to the new URL. A 302 is temporary, signalling the move is short-lived, so the original URL keeps its ranking. Use 301 for permanent moves and 302 for short-term changes like A/B tests or seasonal sale pages.
Where do I put the generated rules?
Paste the generated lines into the .htaccess file in your site root (or the relevant directory). Apache reads them on the next request — no restart needed. Make a backup of your existing .htaccess first.
Does it use Redirect or RewriteRule?
For simple path-to-URL moves it outputs mod_alias Redirect directives, which are the cleanest. You can switch to mod_rewrite RewriteRule output if you prefer or if mod_alias is unavailable on your host.
Will a 301 redirect hurt my SEO?
No — a correctly configured 301 preserves nearly all of the original page's ranking signals and passes them to the destination. Problems only arise from redirect chains, loops, or pointing many old URLs to an irrelevant page (a soft 404). Redirect each old URL to its closest equivalent and keep chains to a single hop.
Does this work with Nginx or only Apache?
The output is Apache .htaccess syntax (mod_alias and mod_rewrite). Nginx does not read .htaccess files — it uses return 301 and rewrite directives in the server block instead. If your host runs Nginx, LiteSpeed with Apache compatibility, or cPanel, .htaccess will usually work; on pure Nginx you will need to translate the rules.
Can I generate bulk redirects with this tool?
Yes — click "+ Add row" to add as many old-to-new URL pairs as you need. All rows are processed in one click and the output is a single block of .htaccess rules you can paste directly into your file. There is no limit on the number of rows.
How do I redirect an entire old domain to a new domain in .htaccess?
To redirect all traffic from an old domain to a new one, add this to your old domain's .htaccess: RewriteEngine On followed by RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com [NC] and RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]. This preserves the URL path on the new domain and passes all ranking signals.
How do I test that my .htaccess redirect is working?
Run: curl -I https://yoursite.com/old-path in your terminal. The response should show "HTTP/1.1 301 Moved Permanently" (or 302) and a Location header pointing to your new URL. You can also use browser DevTools → Network tab and look for the 301/302 response on the old URL.
What causes a redirect loop in .htaccess?
A redirect loop occurs when a rule's destination redirects back to its source — A redirects to B, and B redirects to A, or A redirects to itself. Apache returns a 500 error. Always check that your new URL is not itself subject to another redirect rule in the same file.

How to create bulk .htaccess redirects

Click + Add row to add as many old-path → new-URL pairs as you need. All rows are generated in a single click and output as one clean block you can paste directly into your .htaccess file. There is no row limit.

For very large redirect lists (hundreds of URLs), consider grouping rules by directory to keep the file readable, and place more specific paths above broader pattern rules to avoid premature matches.

Real .htaccess redirect examples

Here are the most common redirect scenarios and the exact .htaccess code for each:

301 redirect a single page (mod_alias)

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

301 redirect using RewriteRule (mod_rewrite)

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

Redirect entire old domain to new domain (preserve path)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]

Force HTTPS (redirect HTTP to HTTPS)

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

Remove www (redirect www to non-www)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

Redirect a removed product to category page (302 temporary)

Redirect 302 /products/old-product https://example.com/products

Related tools

JSON Formatter →   Base64 Encoder / Decoder →   All tools →