How to Force the non-WWW Version of a Domain Name
Force the Root Domain for Your Website using .htaccess
This one is useful since some websites want to have a shorter URL (better for SEO). This will redirect the www subdomain to domain root (non-www). This is for when you want the non-www version of their domain to be the main domain name. People might try going to the www version, so this code redirects them to the non-www version.
Note: Adding “www.” to the front of a domain name actually makes it a sub-domain of the main domain name – just like if you had something like blog.yourdomain.com.
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]I find this code useful when trying to verify an SSL certificate (via the .well-known method). GoDaddy says that they check for both the www and non-www version but no, they just check for the non-www version and when your website is forcing www, this can be a problem – your site switches to the www version and you can’t get it verified.
In that case, put this code in a separate .htaccess file in the /.well-known/pki-validation folder and it should then verify just fine. If it doesn’t, then you have some server settings that are forcing a certain version of the domain name.
Learn more about how to install an SSL certificate on a WordPress website.
📄 Download a PDF of This Article
