How to change a domain name and keep a good ranking?
In SEO, you will capitalize on your URLs.
The sustainability of the URLs is extremely important, not to say essential.
Changing a domain name (or switch to HTTPS) means that all the URLs of your website will change.
It is therefore necessary to indicate to the search engines that they have to pass on the history and popularity of your old URLs to the new ones, otherwise, you should have to start over and therefore lose all the SEO work you've already done.
Start by setting up redirects for all URLs. Both Internet users and search engines will have to be redirected to the new URLs when they'll try to access the old ones.
They also have to be redirected to the same content. If the content has disappeared from your new website, then the redirection will have to lead to the most similar content.
Please, never redirect the whole pages to your homepage. You would then lose most of your initial SEO.
In order to indicate to the search engines the final aspect of these changes and make them detecting the transfer of popularity, the redirections must systematically send out the HTTP 301 header (Moved Permanently).
Finally, notify the change of so main through the Google Search Console , as well as for your analytics.
Don't forget either to update your XML sitemap and, if possible, change the targets of your major backlinks.
Be responsible and implement this system right from the change. Anyways, you will probably suffer from a short-term traffic decrease.