301s, domain moves, HTTPS and canonical rules without tears.
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Whole-domain migration
RewriteCond %{HTTP_HOST} ^old-example\.com [NC]
RewriteRule ^(.*)$ https://new-example.com/$1 [L,R=301]
# Individual redirects
# /old-page → /new-page
RewriteRule ^old-page/?$ /new-page [R=301,L]🔧 Requires Apache with mod_rewrite enabled (near-universal on shared hosting). Place your rules before any conflicting blocks. Test with R=302 first and switch to R=301 once verified, so browsers don’t cache a wrong permanent redirect.
Apache applies RewriteRules top-down; the HTTPS and canonical-host blocks must precede individual redirects or they will chain through them and leak intermediate URLs into browsers.
Browsers cache 301s aggressively and there is no reliable un-cache. Ship new rules as R=302, verify every path, then flip to R=301. This generator emits 301 because that is the end goal.
The whole-domain block preserves paths automatically: old.com/any/path lands on new.com/any/path with one rule instead of thousands of lines. Update Search Console afterward to speed reindexing.
If directives seem ignored, check AllowOverride in the vhost config — shared hosts enable it; some performance-tuned setups disable .htaccess entirely in favor of main config.
More tools you might find useful
Escape HTML special characters to prevent XSS attacks.
Convert HTML entities back to readable characters.
All 62 IANA status codes searchable by number or keyword, with fixes.
Registry country lengths plus the ISO 7064 mod-97 checksum, in your browser.