---
title: Free .htaccess Redirect Generator
slug: htaccess-redirect-generator
last_reviewed: 2026-06-30
author: editorial
source: LemAudit Free Tools
---

## Intro

Most SEO traffic losses during a site migration aren't caused by content changes — they're caused by missing or broken redirects. When you move a page from `/old-blog-post` to `/blog/new-post`, every backlink, every Google index entry, every bookmark needs to forward cleanly to the new URL. Without that, Google drops the old URL from its index, the inbound link equity evaporates, and rankings collapse for a quarter or two.

`.htaccess` is the Apache config file where you put those redirects. It has two formats and the choice between them matters more than most people realize:

- **`Redirect`** (mod_alias) is the simple form. One line per redirect. No regex. Easy to read, easy to break — a single typo silently drops every rule below it.
- **`RewriteRule`** (mod_rewrite) is the recommended form. Supports regex anchors, query-string preservation, conditional rules. More verbose, but far more robust at scale.

This generator outputs either format from a simple list of `/old | /new` pairs. Pick your HTTP status code (301 for permanent SEO migrations, 302/307 for temporary, 308 if you need to preserve POST requests), choose your format, paste your pairs, copy the result into your `.htaccess`.

Two technical details we handle automatically that often get wrong by hand:

1. **Regex escaping.** Paths with dots, parentheses, or `+` characters need to be escaped in `RewriteRule` patterns or they'll match unintended URLs. We escape them for you.
2. **Query-string preservation.** The `[QSA]` flag (Query String Append) on `RewriteRule` makes sure `?utm_source=x` survives the redirect. Without it, every tracking parameter gets stripped — bad for analytics, bad for campaign attribution.

The output always includes a leading comment with the generation date so you can find the block later and a count of the rules included.

## When not to use this

Don't use `.htaccess` redirects if you're not on Apache. Nginx, Caddy, IIS, Cloudflare Workers, Netlify, Vercel, and Fastly all have their own redirect formats and `.htaccess` files are ignored. Check your hosting provider before pasting anything from this tool.

Don't use a single `.htaccess` file for hundreds of redirects. Apache reads the file on every request, so a 5000-line redirect block adds measurable latency to every page load. For migrations with thousands of URL changes, push the redirects into a database table or a Cloudflare Workers rule set, and only keep the most-trafficked rules in `.htaccess`.

Don't use `.htaccess` redirects when an application-level redirect would be cleaner. If you're running WordPress, plugins like Redirection or Rank Math give you a UI for the same job and don't require server config changes. If you control the application code, returning a `301` from your router is often more maintainable than the config file.

## FAQ

### What's the difference between 301 and 308?

Both are permanent redirects. 301 was the original spec and is what most CMSes default to. 308 was added in HTTP/1.1 (RFC 7538) specifically to preserve the request method. With 301, a POST request gets converted to a GET on the redirect destination. With 308, the POST stays a POST. For an SEO migration where you're redirecting GET URLs, 301 is correct and universal. For API endpoint migrations where POST matters, use 308.

### Should I use `Redirect` or `RewriteRule`?

`RewriteRule` is the modern recommendation. It's more verbose but more robust and supports query-string preservation, conditional logic, and regex matching. Use `Redirect` only for very small redirect sets where readability matters more than scalability.

### Why does the generator anchor patterns with `^` and `/?$`?

Without anchors, `RewriteRule old-post` would also match `/old-post-2`, `/old-post-comments`, anything containing that substring. The `^` ties the match to the start of the path; `/?$` matches an optional trailing slash at the end. Together they say "match exactly this path, with or without a trailing slash, and nothing else."

### Does this handle full-URL targets?

Yes — if the target starts with `http://` or `https://`, Apache treats it as an external redirect and sends the full Location header. Use this for redirecting old URLs to a new domain.

### What about HTTPS redirects?

Forcing HTTPS is a different pattern — you need a `RewriteCond %{HTTPS} off` line above the rule. That's a single-rule case better written by hand or generated by your hosting provider's tooling.

### How do I test the redirects before going live?

`curl -I https://yoursite.com/old-path` and check the `Location` header in the response. Or use the redirect-checker mode in [LemAudit](/) — it crawls a list of old URLs and verifies they all return the correct status and destination.
