Usually, you use www.domain, but in some cases, if you have not set up or pointed the domain IP, it will not take effect. In this article, AZDIGI will guide you to use www and no www with a .htaccess file
1. Use www for domain
To use www.domain, you must point www to the hosting IP with an A record; by default, www is also a sub. You open the .htaccess file and add the following code
Note: Replace mydomain with your domain
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^mydomain [NC]
RewriteRule ^(.*)$ https://www.mydomain/\ [L,R=301]
2. On the contrary, if you don’t want www
For a shorter URL for easy brand recognition and think about removing www.domain.
You open the .htaccess file and add the following code
Note: Replace mydomain with your domain
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.mydomain [NC]
RewriteRule ^(.*)$ https://mydomain/\ [L,R=301]
Additional information: In both cases, the 301 parameter is very important, it means permanent redirect, so do not leave this parameter out.