It occurred to me that just maybe you don’t want to display your site with the www subdomain prefix. In that case you could deploy the following code in your .htaccess file to redirect www to non-www. By doing so, users will access your site at http://domain.com not http://www.domain.com.
.htaccess
If your website is hosted on an apache server, a redirect from www to non-www is a simple implementation. Add the following to your .htaccess file.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^domain\.com
RewriteRule (.*) http://domain.com/$1 [R=301,L]
Add the above code to you .htaccess file and replace domain.com with your domain name.
This post is a follow-up to a similar adrticle on how to redirect non-www to www with .htaccess.
It’s is considered good practice, for both SEO and users, to have your website resolve to one URL. Technically speaking www.domain.com is a subdomain of domain.com. Users often type www. prior to the domain in the address bar. So to keep that formality consistent with your users you can redirect the traffic on domain.com to www.domain.com.
The .htaccess file is commonly used to redirect traffic and search engines to pages that have been moved or when an entire site moves to a new domain. Developers will commonly include comments in code to instruct what the next snippet of code will do. This commenting standard helps for projects that are managed by a team or may be transitioned to another developer.