Articles Comments

Redirecting www to non-www using .htaccess

SHARE: Share

Some people like www, some not. I recommend to use only one of the versions, www or non-www.

Here are some codes you can add to your .htaccess file to set up the friendly (301) redirects.

Redirect www to non-www:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]

Redirect non-www to www:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]

None of these versions is better than the other. It is a matter of… I dunno… taste? :)

I like to use the www one if my domain name is a short one, if it is longer, I use the none-www one.

Was this post useful? Buy me a beer. :)

Incoming search terms:

Written by

If you need someone to code/fix your site, contact me here.

Filed under: Web development

Leave a Reply