Here’s how to safely migrate a niche website from an old domain to a new domain. It takes care of www, non www, https and http versions of each possible URL.
It also accounts for specific redirects that you might need to do. It’s important that these are placed above the wildcard domain redirect.
DISCLAIMER: Don’t do any of this unless you really know what you’re doing. I’m not responsible for any errors that happen. Messing around with .htaccess can prevent you from accessing your website and you’ll need to take restoration steps.
Always take a backup first!
RewriteEngine On RewriteBase / # Bypass redirection for wp-admin RewriteCond %{REQUEST_URI} ^/wp-admin/ [NC] RewriteRule .* - [L] # Specific redirects RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com$ [NC] RewriteRule ^old-category/url-1/$ https://new-domain.com/url-new/ [R=301,L] RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com$ [NC] RewriteRule ^old-url/$ https://new-domain.com/new-url/ [R=301,L] RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com$ [NC] RewriteRule ^old-category/$ https://new-domain.com/renamed-category/ [R=301,L] # Redirect all other requests from the old domain to the new domain RewriteCond %{HTTP_HOST} ^(www\.)?old-domain\.com$ [NC] RewriteRule ^(.*)$ https://new-domain.com/$1 [R=301,L]
I hope this helps.
I know it will help me anyway because I always search for this info to double check I’m doing a migration correctly.
You can use ChatGPT for this stuff too, but trust me, it will get things wrong. Multiple times. Check and double check before deploying on your live site.