How to redirect a URL only by changing the domain name while maintaining other URL parameters

Now I am transferring my site to a new host and domain, and I want to know if I can redirect everyone who enters any URL of the old site to the new website, keeping all the URL parameters. eg:

When someone types this url http://www.domainA.com/blog/?p=667 , I want it to redirect to http://www.domainB.com/blog/?p=667 .

Is there a way to do this by adding some .htaccess configurations?

Thanks!

+4
source share
1 answer

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.

+4
source

All Articles