For SEO it is extremely important to standardize on either the www-prefixed version of the domain or the non-prefixed version and Permanently (301) redirect all requests from the one not in use to the primary one. Not implementing this rule is to ensure you will suffer duplicate content penalties in search engines.

Enforce www prefix

To canonicalize to a www prefixed domain, add the following rule to your .htaccess or virtual host config:

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

This rule above causes all requests to http(s)://example.com/ to be redirected to https://www.example.com/. For SEO purposes this redirect should be Permanent (301).

Enforce non-www prefix

To canonicalize to a non-www prefixed domain, add the following rule to .htaccess or virtual host config:

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

This rule causes all requests to http(s)://www.example.com/ to be redirected to https://example.com/.