1 · Sitewide recipes
2 · Redirect rules
0 rules .htaccess Redirect Generator
Regex-free Apache rules for the redirects that matter: permanent 301s, temporary 302s, HTTPS upgrades, canonical hosts and whole-domain moves — generated in the correct order, ready to paste.
Four codes, four different messages to Google
The number in brackets is the whole point — it decides whether rankings transfer, whether the old URL stays indexed, and whether POST bodies survive.
Moved Permanently
The SEO redirect. Permanently moves a URL and transfers ranking signals to the target. Browsers cache it aggressively — which is exactly what you want for migrations, slug changes and HTTPS upgrades.
Migrations, renames, HTTPS
Found (Temporary)
Tells search engines the move is temporary, so the original URL stays indexed and keeps its rankings. Perfect for A/B tests and maintenance pages — dangerous if forgotten in place for months.
Tests, campaigns, maintenance
Temporary Redirect
The strict modern 302: the redirected request must repeat with the same HTTP method, so a POST stays a POST. Choose it for API endpoints and form flows where method preservation matters.
APIs, forms, method-safe hops
Permanent Redirect
A 301 with guaranteed method preservation. Supported by all modern browsers and Google treats it like a 301 for ranking purposes. Slightly less universal on very old clients.
Permanent moves with POST bodies
The six rules that cover 95% of redirects
Every one of these is a toggle or a text field in the generator — no regex required. Preview the Apache output before you commit it to production.
Force HTTPS everywhere
Upgrade every HTTP request to TLS in one hop.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] Remove www (canonical host)
Collapse www.example.com to example.com.
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301] Force www
Send bare-domain traffic to the www host.
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301] Whole-domain migration
Move every URL to a new domain, path intact.
RewriteCond %{HTTP_HOST} ^(www\.)?old\.com$ [NC]
RewriteRule ^ https://new.com%{REQUEST_URI} [L,R=301] Single page 301
One old path to one new URL via mod_alias.
Redirect 301 /old-page https://example.com/new-page Strip .html extensions
Redirect /about.html to the clean /about URL.
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*)\.html$ /$1 [L,R=301] Anatomy of a rewrite rule
Every generated rule follows the same shape: an engine directive, zero or more conditions, then the rule itself. Read it once and cryptic regex turns into a sentence.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-site\.com$ [NC]
RewriteRule ^(.*)$ https://new-site.com/$1 [R=301,L] - 1
RewriteEngine OnActivates mod_rewrite for this directory context. Without it, every rule below is dead text.
- 2
RewriteCond %{HTTP_HOST} ^old-site\.com$ [NC]The gate: this rule only fires when the Host header matches. [NC] makes the match case-insensitive.
- 3
RewriteRule ^(.*)$ …The pattern ^(.*)$ captures the requested path. Note .htaccess rules see paths without the leading slash.
- 4
… https://new-site.com/$1The substitution. $1 re-inserts the captured path, so /about becomes https://new-site.com/about.
- 5
… [R=301,L]The flags: R=301 issues a permanent redirect; L stops processing so nothing below can override it.
Order is everything
Apache reads rules top to bottom and the first match with [L] wins. The generator emits blocks in this sequence automatically — so a CMS catch-all can never swallow your redirects.
- 1
Domain moves
Whole-site host changes fire first so old URLs never hit later rules.
- 2
HTTPS upgrade
Force TLS before host rules to collapse http+www hops into one redirect.
- 3
Canonical host
www vs non-www normalization — combine with HTTPS to avoid chained hops.
- 4
Page-level rules
Individual 301/302s from most specific path to most general.
- 5
Front controller
CMS catch-alls (like WordPress rewrite to index.php) always go last — they swallow whatever remains.
Where .htaccess rules go wrong
Redirect chains
old → http → https → www → new burns crawl budget and dilutes link equity. Combine conditions so every URL reaches its final form in exactly one hop.
Loops behind a proxy
On Cloudflare or a load balancer, %{HTTPS} may always read "off" because TLS ends upstream. Check X-Forwarded-Proto instead — or the HTTPS rule loops forever.
Forgetting the [L] flag
Without L, Apache keeps evaluating every rule after yours. Two matching rules produce mangled targets or double redirects that are miserable to debug.
A 302 that outlives its welcome
Left in place for months, a "temporary" 302 tells Google to keep the old URL indexed — the new one never fully inherits its rankings. Audit temporary redirects quarterly.
Safety habit: test new rules on a staging copy or a private browser window first — browsers cache 301s hard, and a cached bad redirect outlives the fix.
.htaccess questions, answered
From SEO impact to the proxy loop that catches everyone eventually.
What is the difference between a 301 and a 302 for SEO?
A 301 tells search engines the move is permanent — link equity consolidates onto the new URL and the old one drops out of the index. A 302 keeps the original URL indexed because the move is supposed to be temporary. Using a 302 for a permanent move is one of the most common ways migrations leak rankings.
Where do I put the .htaccess file?
In your document root — the same directory as your homepage (often public_html/ or www/). Rules in a root .htaccess apply to the whole site; a file inside /blog/ governs only that folder. The file has no extension — it is literally named .htaccess.
Will these rules work on Nginx?
No. Nginx does not read .htaccess files at all — that is an Apache-only mechanism. On Nginx, redirects belong in the server block of nginx.conf using return or rewrite directives. The generated logic still maps one-to-one; only the syntax changes.
Why is my HTTPS redirect looping forever?
Almost always because you are behind a proxy or CDN. The proxy terminates TLS and forwards plain HTTP to Apache, so %{HTTPS} is always "off" and the rule fires on every request — including HTTPS ones. Test %{HTTP:X-Forwarded-Proto} instead, or handle the upgrade at the CDN layer.
How long should 301 redirects stay in place?
Google recommends keeping them live for at least a year after a migration — longer is better. Inbound links and bookmarks last for years, so high-traffic redirects ideally stay forever. Removing a 301 does not instantly lose rankings, but the old URL gradually reverts to a 404.
How many redirects in a chain is too many?
Googlebot gives up around ten hops, but every extra hop dilutes link equity, wastes crawl budget and adds latency for users. The correct number is one: combine HTTPS and host rules so a single redirect carries the visitor to the final canonical URL.
Generate, then verify the chain
Writing the rule is half the job — these tools confirm it actually behaves.
Redirect Checker
Trace redirect chains, detect loops, and verify status codes.
SSL Checker
Verify SSL certificates, HTTPS config, and security headers.
Canonical Tag Generator
Generate canonical link tags to prevent duplicate content issues.
Robots.txt Generator
Build a robots.txt file with AI crawler support for GPTBot, ClaudeBot, and more.
One hop. Zero regex anxiety.
Every wrong redirect costs a visitor or a ranking. Generate rules that send each URL straight to its final home — verified order, correct flags, production-ready.