Generate correct, copy-paste .htaccess redirects: force HTTPS and www (or non-www) in a single hop, map hundreds of old URLs to new ones, or move a whole domain. Everything runs in your browser.
Put the rules at the top of the .htaccess in your document root, before any CMS block (WordPress, Laravel...). Test with curl -sI http://example.com/old-page and the redirect checker.
How to use the .htaccess redirect generator
Pick a tab, fill in the fields, and the rules appear below as you type, ready to copy or download as .htaccess. Nothing is sent to a server: the generator runs in your browser, and the settings live in the page address, so Copy link to these settings gives you a URL you can bookmark or send to a colleague.
- HTTPS & www builds the canonical-URL block every site needs: force HTTPS, pick www or non-www, remove
index.php, and add or remove the trailing slash. - 301 redirects (bulk) turns a list of old and new URLs into exact-match rules. Paste hundreds of lines from a spreadsheet or a crawl export.
- Domain move sends an old domain, with or without www, to a new one and keeps every path.
Every result has a Test these rules button that opens them in the .htaccess tester, so you can watch Apache's decision for any URL before you upload anything.
Which redirect status should I use?
- 301 Moved Permanently: the page has a new home for good. Search engines move rankings and links to the new URL. This is the right choice for almost every migration.
- 308 Permanent Redirect: like 301, but browsers must repeat a POST as a POST. Use it for APIs and form endpoints.
- 302 Found and 307 Temporary Redirect: the old URL will come back. Search engines keep the old URL indexed. 307 keeps the method, 302 may turn POST into GET.
- 410 Gone: the page is removed on purpose and has no replacement. Google drops it faster than a 404.
Force HTTPS and www in one hop
The classic mistake is two separate rules: one sends http://example.com to https://example.com, the next sends that to https://www.example.com. That is a redirect chain: two round trips for every visitor and every crawler. The generator writes a single rule that fixes the scheme and the host at once:
RewriteEngine On
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L,NE]
NE keeps percent-encoded characters intact, so /caf%C3%A9 is not double-encoded. Behind Cloudflare or a load balancer the TLS connection ends at the proxy and %{HTTPS} is always off on your server; tick the proxy option and the rule reads X-Forwarded-Proto instead.
Bulk 301 redirects: exact match vs prefix match
Redirect 301 /old /new from mod_alias looks simple, but it is a prefix match: it also sends /old/anything to /new/anything, and /older is untouched only by luck. The generator defaults to exact-match RewriteRules and handles the details people get wrong:
- Apache matches the decoded path, so a source like
/caf%C3%A9is written as/café. - A
?queryin the old URL becomes aRewriteCond %{QUERY_STRING}, becauseRewriteRulenever sees the query string. - The old query string is dropped with
QSDunless you ask to pass it along. - Duplicates, redirects to themselves (loops) and redirects that point at another redirect (chains) are flagged before you upload them.
Where do the rules go?
Put them at the top of the .htaccess in your document root, above any CMS block such as WordPress's # BEGIN WordPress. Rules run in order, and a front-controller rule would otherwise catch the old URLs first. Then check the result with curl -sI http://example.com/old-page or the redirect checker.
FAQ
Does a 301 redirect lose SEO value?
No. Google passes ranking signals through 301 and 308 redirects. What does lose value is a chain of several hops, a redirect to an unrelated page (treated like a soft 404), or a temporary 302 left in place for a permanent move.
Why do I get "too many redirects"?
A rule matches its own target. The most common cause is an HTTPS rule behind a proxy that checks %{HTTPS}, which is never on there. Run the rules through the .htaccess tester to see the loop.
How long should I keep redirects after a migration?
At least a year, and longer for pages with inbound links. Keep the old domain registered with valid DNS and certificate for as long as the redirects matter.
Can I redirect without mod_rewrite?
Yes: choose Redirect or RedirectMatch in the method menu for mod_alias rules. Query-string matching and multiple domains still need mod_rewrite.