Redirect www to non-www URLs

If you want redirect users from www to a plain, non-www domain, insert this configuration in your .htaccess file:

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

Save and exit. The changes should go into effect immediately. Note that if you are using HTTPS, you should update “http”, in the RewriteRule line, to “https”.

Use this curl command to ensure that the non-www domain redirects to the www domain (replace the highlighted part with your actual domain):

curl -I

You should get a 301 Moved Permanently response, that shows the non-www redirect location, like this:

HTTP/1.1 301 Moved Permanently
Date: Fri, 01 May 2015 21:18:33 GMT
Server: Apache/2.4.7 (Ubuntu)
Content-Type: text/html; charset=iso-8859-1

Of course, you should access your domain in a web browser (www and non-www) to be sure.