My experience to redirect non www to www on WordPress and Hostgator. Check with your hosting provider if not Hostgator.
After activating SSL (https) now its time to redirect from non www to www. This is optional you can redirect non www to www or redirect www to non www (naked domain), depends on your preferences.
The website is based on WordPress CMS version 5.3.2 and using Hostgator as the hosting company. On their manual here said that I need to add
RewriteCond %HTTP_HOST} ^domain.com$ RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
on the .htaccess file (I edit this file via the file manager on CPANEL)
When I add the code it doesn’t changed, it still redirect no non www. I didn’t understand why the code is not redirecting. I am sure that the code is correct because the source is from HostGator itself.
Then I check with http://www.redirect-checker.org/ and found that the WordPress did the redirection. Knowing this I then logon to WordPress’s Darshboard and click on Settings – General.
I found it still using https://domainname.com on WordPress address and Site address section. Then I changed both to https://www.domainname.com
When I check it’s now working correctly as I want it to.