Try this in your .htaccess file:
Options +FollowSymlinks -MultiViews RewriteEngine on # for http RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC] RewriteCond %{SERVER_PORT} =80 RewriteRule ^(.*)$ http://www.domainB.com/$1 [R=301,L] # for https RewriteCond %{HTTP_HOST} ^(www\.)?domainA\.com$ [NC] RewriteCond %{SERVER_PORT} =443 RewriteRule ^(.*)$ https://www.domainB.com/$1 [R=301,L]
This will save your URI when redirecting from domain A to domain B.
source share