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.
5 replies on “How to Add www. – or Remove www. – From Your URL”
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!
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!
Hey, great article. What about Zeus types of servers where htaccess. files is not supported?
It looks like http://www.realisingdesigns.com/2008/07/30/zeus-webserver-redirect-non-www-to-www-site/ is a good way to do that.
Thanks, works great!