Its very rare that anyone changes main domain of website, but its still possible. The main issue which you may face while shifting to new domain is how to redirect all URLs to their appropriate new domain URLs.
For example, yourolddomain.com/some_blog_post should NOT redirect to just yournewdomain.com
Ideally, it should redirect to yournewdomain.com/some_blog_post
You may ask why its necessary to redirect exactly to same page? Well, good question. Its important from a SEO view point. If your old domain is very old, chances are that you must be having some good SEO score, and you don’t want that to go to drain. Using exact redirection, we can borrow the old site SEO score to new site. This is also important to maintain the search listing location on Google and similar search engine websites.
Now, lets get to the good stuff, how to redirect?
Requirements: Knowledge of creating file on server, hosting for old domain.
If you are using cPanel, you can easily follow below tutorial. If you are using other control panels or FTP, process is very similar.
Login to cPanel, goto File Manager and navigate to your root directory of domain. (Usually, it is something like public_html or public)
Create a new file .htaccess
Edit that newly created file and paste following content.
RewriteEngine on RewriteRule ^(.*)$ http://NEWDOMAIN.COM/$1 [R=301,L]
Make sure you change NEWDOMAIN.COM with your own domain name.
Incase if you are not able to see .htaccess file, click on “Settings” button (top right corner) and enable checkbox “Show Hidden Files”
That’s it! Now, check if all the links are redirecting properly or not. You can do the same process for any sub domains you have in your website.
Using .htaccess is one of the simplest way to redirect traffic. However, you can also utilize other methods like DNS, Domain provider’s redirection, etc.