Htaccess Redirect Generator: How It Works
A redirect tells browsers and search engines that a URL has moved. Getting the type and the ordering right preserves the ranking value a page has accumulated; getting it wrong loses that value or creates loops that take a site offline.
Choosing the status code
| Code | Meaning | Use for |
|---|---|---|
| 301 | Moved permanently | Almost all SEO redirects — passes ranking signals |
| 302 | Found (temporary) | Genuinely temporary moves, A/B tests, maintenance |
| 307 | Temporary, method preserved | Temporary redirects that must not change POST to GET |
| 308 | Permanent, method preserved | Permanent moves on API endpoints |
| 410 | Gone | Content deliberately removed with no replacement |
The common error is using 302 for a permanent move. Search engines treat a temporary redirect as a signal to keep the original URL indexed, so ranking value stays stranded on a URL that no longer serves content.
The rules that make Apache configuration work
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# Force www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
# Single page move
Redirect 301 /old-page /new-page
# Whole directory
RewriteRule ^old-section/(.*)$ /new-section/$1 [R=301,L]- Order matters. Rules run top to bottom; the
Lflag stops processing for that pass. RewriteCondapplies only to the rule immediately following it. This trips up nearly everyone writing their second rule.- Test on a copy. A syntax error in
.htaccessproduces a 500 across the entire site, not just the affected path.
Chains and loops
A chain is A → B → C. Each hop adds latency and search engines may stop following after several. Always redirect directly to the final destination and update the earlier rules when a target moves again.
A loop is A → B → A, which produces a 'too many redirects' error and takes the page completely offline. The usual cause is two rules — commonly an HTTPS rule and a www rule — written without conditions that exclude the state each other produces.
Redirect to the equivalent page
A redirect passes value only when the destination is genuinely a replacement. Mass-redirecting hundreds of deleted pages to the homepage is treated as a soft 404: the value does not transfer, and the user experience is poor. If there is no equivalent page, returning 410 is more honest and gets the URL removed cleanly.
Site migration checklist
- Map every old URL to its closest new equivalent before launch.
- Implement 301s for the whole map, not just top pages.
- Update internal links to point at the new URLs directly, not through redirects.
- Update the sitemap and resubmit it.
- Keep the old sitemap available briefly so old URLs are recrawled and the redirects discovered.
- Retain the redirects indefinitely — external links keep arriving for years.
Performance
Rules in .htaccess are read on every request, so hundreds of them measurably slow a site. Where you have server configuration access, moving rules into the main virtual host config is significantly faster. For very large redirect maps, a database or map-file lookup outperforms a long list of individual rules.