This occurs because browsers look for the correct security credentials first to avoid improper redirects. Rewrites in an htaccess file do not solve the problem. You should first allow browsers to connect securely then use rewrites to redirect to the new domain.
One way to correct this issue is to use a Virtual Host. Virtual Hosts allow one IP address to host multiple domains. This is easy if you are using a Synology server. Fortunately hosting providers usually provide a way to run Virtual hosts as well. When you configure the virtual host, use the domain name-based option. Enter your old domain name using the default port settings which is 80 for HTTP and 443 for HTTPS. In the document root window, enter the path to the root of your new website. You may be required to select a backend server (nginx, Apache, etc) and the php version you want to use. Make your selections, then save the virtual host and exit. Two virtual hosts may be required if you had both WWW and non-WWW websites. Just create two virtual hosts, one with WWW and one without.
Open the server or host control console and locate the security or SSL certificate options. The new SSL certificate should be the default certificate for the new domain name. Hopefully you did not delete the old SSL certificate for your prior domain. If you deleted the old certificate, install it again. Then select the old certificate and configure it for the virtual host(s) you just created. If the old certificate has expired, it must be renewed if you want to allow connections to use your old domain name without errors.
Once you've completed the above instructions, redirects in your htaccess file should work correctly. There are many examples of redirect codes online that perform various functions. Some sample codes are shown below. If you copy and paste, remember to replace the example names with your domain names.
Code: Select all
RewriteEngine On
RewriteBase /
## check if user connected using the old domain name
RewriteCond %{HTTP_HOST} ^old_domain_name$
## they did so redirect to the new domain name
RewriteRule ^(.*)$ https://new_domain_name/$1 [R=301,L]
Code: Select all
RewriteEngine On
## check to see if the current connection is HTTPS
RewriteCond %{HTTPS} !=on
## it is not so force a HTTPS connection
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
Note: these instructions apply to domain name changes on the same host or server.