htaccess domain redirect, the proper way [2021 edition]

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 ^(.*)$$1 [R=301,L]

htaccess redirects – things to consider

  1. Always backup your server before a migration
  2. 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
  3. 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, should go to The code I provided above works for that.

Leave a Comment

Your email address will not be published. Required fields are marked *