Normally, I write here about Conversion Rate Optimization, but recently, i had to do domain migration and all the guides on the first page of google were not helpful, so I think it’s the right thing to do and share some of the learnings from the process.
I spent three hours trying to figure out how to properly do a htaccess redirect from and old domain to a new one without loosing any pages. Some guides worked partially, some didn’t work at all.
Finally, I found this article and wanted to share the code that made it all work!
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
</IfModule>
htaccess redirects – things to consider
- Always backup your server before a migration
- When you modify htaccess through a plugin like Rankmath, you will not be able to enter /wp-admin/ , so if you mess up, you need to restore a backup
- It all depends on how and what you want to move. In my case I wanted to move all the posts, pages etc and use the same urls. For example, domainA.com/post1 should go to domainB.com/post1. The code I provided above works for that.