How to Add www. – or Remove www. – From Your URL

Add or remove .www from your site's address

This has been done many times by others, but just a quick tip on how to add or remove www. from your website’s address. This is helpful for URL canonicalization and user experience consistency. You can also achieve SEO-friendly canonicalization using rel="canonical". Oh boy, I’m getting too technical :-)

Here’s the juicy part:

Add the following to the .htaccess file in your website’s root folder (often named public_html or www). If there’s not a file named .htaccess, you may create it. If you are creating the .htaccess file, set the permissions to 644. For security reasons, you don’t want others to be able to write to this file.

Note: These snippets are for http:// only, not secure https:// URLs.

Add www.


Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com/?(.+)?$
RewriteRule ^(.*)$ "http\:\/\/www\.example\.com/$1" [R=301,L]

Remove www.


Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,NC,L]

This will work with the majority of web hosts in my experience, but not all.

Additional resources

For more .htaccess information, and great follow-up reading on .htaccess, check out corz.org’s tutorial and second tutorial on some of the most-used .htaccess tricks.

This entry was posted in QuickTip, Web Development and tagged , , , , , , , , . Bookmark the permalink.
  • http://discovering-denver.blogspot.com Discovering Denver

    Thank you for explaining how to remove www. No one wants to type that any more. I appreciate all of the useful info on this site!

  • http://seo.johndetlefs.com seo sydney

    This absolutely works! I’m pretty sure there are some plugins that you can use to get it done if you’re using WordPress as well. Anyway, thanks for the tips!

  • Grybas2010

    Hey, great article. What about Zeus types of servers where htaccess. files is not supported?

  • Tim

    Thanks, works great!