.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.
How to generate .htaccess redirect rules
- 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. - Choose the redirect type — 301 permanent or 302 temporary — and the directive style (Redirect or RewriteRule).
- Click Generate rules, then Copy the output and paste it into the
.htaccessfile 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 |
|---|---|---|
| Meaning | Page has moved for good | Move is short-lived |
| Link equity | Passed to new URL | Kept on original URL |
| Indexed URL | Destination replaces source | Source stays indexed |
| Browser caching | Cached aggressively | Re-checked each visit |
| Use it for | Renames, domain moves, HTTP→HTTPS | A/B tests, sales, maintenance pages |
Common use cases
- Site restructure: point old slugs like
/blog/2019/my-postto their new home after changing your URL scheme. - HTTPS or www migration: consolidate
http://and non-wwwvariants 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
/demoto a longer campaign URL.
Tips & gotchas
- Back up first. Save your existing
.htaccessbefore 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
Redirectwith overlappingRewriteRuledirectives, as they can fire twice and stack query strings. - Test before you trust. Verify each rule with
curl -I https://yoursite.com/old-pathand confirm the status line reads301or302.
Frequently asked questions
Is this .htaccess redirect generator free and private?
What is the difference between a 301 and a 302 redirect?
Where do I put the generated rules?
Does it use Redirect or RewriteRule?
Will a 301 redirect hurt my SEO?
Does this work with Nginx or only Apache?
Can I generate bulk redirects with this tool?
How do I redirect an entire old domain to a new domain in .htaccess?
How do I test that my .htaccess redirect is working?
What causes a redirect loop in .htaccess?
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