How to use the .htaccess Redirect Generator
.htaccess is Apache's per-directory configuration file. Used right, it normalizes URLs and routes redirects without touching application code. Used wrong, a single bad rule can take down the entire site.
Pick the redirect type
301 for permanent moves (passes ranking signals). 302 for temporary (no ranking transfer). 99% of SEO redirects are 301.
Specify source and destination
Source can be a literal path (/old-page) or a regex pattern (^/old-section/(.*)). Destination is the target URL or pattern.
Add common patterns (optional)
Force HTTPS, force www or non-www, add or strip trailing slashes, redirect index.html to root. The generator includes templated rules for each.
Place in .htaccess at the directory root
Upload the .htaccess to the directory you want the rules to apply to. Usually the document root. Test on a staging server first — bad rules can return 500 errors.
Why .htaccess redirects matter for SEO
URL changes are inevitable — redesigns, migrations, slug updates, HTTPS rollouts. Each change creates redirect debt. A clean .htaccess with proper 301s preserves ranking signals; a chain of 302s and broken redirects loses them.
301 vs 302
302 (Found / Temporarily Moved) says "use the new URL for now but the old one will return." No ranking signals transfer. Use for A/B tests, maintenance pages, and genuinely temporary routing.
Common .htaccess patterns
- Force HTTPS —
RewriteCond %{HTTPS} off+RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]. - Force www — redirect non-www to www (or vice versa). Pick one and stick with it.
- Trailing slash normalization — either always or never. Inconsistency creates duplicate URLs.
- Single-page redirect —
Redirect 301 /old-page /new-page. - Pattern redirect —
RewriteRule ^/blog/old-(.*)$ /blog/$1 [L,R=301].
Three rules that destroy SEO
- Chain redirects — A → B → C → D loses signal at each hop. Always 1-hop.
- Redirect everything to homepage — Google treats as soft 404s, kills ranking transfer.
- Mix 301 and 302 inconsistently — confuses crawlers and slows reindexing.
Frequently asked questions
What's the difference between 301 and 302 redirects?
301 is permanent — search engines transfer ranking signals from the old URL to the new one. 302 is temporary — no signal transfer, the old URL is expected to come back. For SEO migrations, slug changes, and HTTPS rollouts, always use 301. 302 is rarely correct outside A/B tests and maintenance.
Where do I put .htaccess?
In the directory you want the rules to apply to. For site-wide rules, the document root (where index.html lives). For per-directory rules, the specific directory. Apache reads .htaccess from each directory traversed during the request, so rules cascade.
Will .htaccess redirects pass PageRank?
Yes — 301 redirects pass essentially all ranking signals from old to new URL. The transfer takes a few weeks to fully propagate as Google re-crawls. 302 redirects do not pass signals — they're treated as "same content, different URL temporarily."
What happens if my .htaccess has a syntax error?
Apache returns a 500 Internal Server Error to all requests in that directory. The site goes down until you fix the file. Always test .htaccess changes on staging first, and keep a backup of the working version before editing production.
How many redirects can I chain?
Technically unlimited, but Google starts ignoring chains after 4–5 hops. Each hop also slows page load. Best practice: collapse chains to single hops. If A redirects to B redirects to C, change A to redirect directly to C.