How to redirect your old domain to a new domain using .htaccess

If you need to change your domain from an old domain to a new domain but the over all structure of your website is not changing, you can use the following .htaccess to redirect without impacting your SEO. Sometimes when changing domains, website owners don't properly implement redirects and it can cause SEO to start over as if it was a new website.

  RewriteEngine On
  RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
  RewriteCond %{HTTP_HOST} ^www.olddomain.com$
  RewriteRule (.*)$ https://www.newdomain.com/$1 [R=301,L]

This code should be placed in the .htaccess file in your public_html directory. Don't forget to change olddomain.com and newdomain.com to your domains.

This will redirect to the same path on your new website. For example, if you redirect https://www.example.org to https://www.example.com, this will update all your existing links so that https://www.example.org/product/details.php?id=12 will automatically redirect to https://www.example.com/product/details.php?id=12. 

The 301 redirect code means moved permanently. Search engines will treat this as your existing site and not a new site. Therefore your SEO will not be impacted.

Article Information
  • Article ID: 340
  • Category: Web Hosting
  • Viewed 203 times.
  • Rating:
    (0)
  • Was this article helpful?
  • Yes No
Did you find this article helpful?