Possible Duplicate:
What’s the point in having "www" in a URL?

Should I use www in front of a URL or not? Some sites say we should and some say the opposite.

If there is no www is in front of the URL, what should I put in my .htaccess to rewrite the URL and optimise my site for search engines?

  • no-www does NOT want people to stop using the www. prefix. They want sites to accept traffic with and without the prefix.
    – Matt Ball
    Dec 10, 2009 at 21:31
  • 15
    It's silly that the abbreviation for a 3-syllable phrase "world wide web" is pronounced with 9 syllables.
    – Joe Koberg
    Dec 10, 2009 at 21:33
  • @JoeKoberg Good catch, people don’t pronounce www like an abbreviation (etc. > "et cetera") but like an initialism (I.M.F. > "high-em-ef").
    – Géry Ogam
    Apr 24, 2020 at 15:31

6 Answers 6


Yes, it's best (SEO wise) to have one redirecting to the other. You want to avoid content duplication and link-juice fragmentation (although those 2 should be have been fixed by now on the major search engines).

<VirtualHost *:80>
    ServerAlias www.example.com
    RedirectMatch permanent ^/(.*) http://example.com/$1

Keep in mind though that the no-www movement has the disadvantage that all subdomains will be also transfering the cookies of the main (no-www) domain.

  • 2
    I also add ServerName example.com so it knows what the site name actually is. Also there can be many ServerAliases for each Vhost entry.
    – Joe Koberg
    Dec 10, 2009 at 21:32
  • 1
    You don't need the RedirectMatch; a plain Redirect permanent / http://example.com/ does the same thing.
    – bobince
    Dec 14, 2009 at 3:53
  • @Cherouvim, refusing to use the "www" subdomain doesn't preclude the use of other useful subdomains; especially for static/no-cookie domains or similar purposes. No-WWW is about simplifying the URL, making it more elegant, and removing something that's virtually extraneous in our modern Internet. The "www" subdomain is a archaic appendix left over from the days of ArpaNet. We should be moving away from it in droves.
    – Chris S
    May 27, 2012 at 2:31
  • 1
    @ChrisS: Yes but if you server images from static.example.com then it'll also transmit all cookies of example.com without a reason. That's why you'll usually need a static-images-of-example.com (a completelly different domain. That's what stackoverflow, facebook etc do.
    – cherouvim
    May 27, 2012 at 6:28

Certainly 301 one to the other.

It's necessary to make the www. the canonical version when you envisage you might at some point have other hostnames/subdomains under the same domain, with their own security contexts.

If you plump for the non-www. version, you won't be able to set cookies on the main example.com site without also making them available to anything on subdomain.example.com. If the subdomain is something like a userimg.example.com where you're trying to host user-submitted data with lower security rights, the non-www. version will be leaking cookies which the www. version would keep separate.

(Plus of course the other non-web-related stuff, like not being able to CNAME a bare domain.)


There's no good reason not to provide both.

  • 5
    content duplication and link-juice fragmentation used to be 2 reasons
    – cherouvim
    Dec 10, 2009 at 21:33
  • Heads up about this situation: stackoverflow.com/questions/570148/… Dec 10, 2009 at 21:37
  • Google isn't the only search engine, the big players may have fixed the problems but depending on your site content and target you may be getting search engine traffic from sources other than the big players. Dec 10, 2009 at 21:39

It's up to you. A matter of taste. Point.

Having a shorter version (without www) may have SEO implications. The short an URL is, the more relative weight its keyword may have.

Pay attention that you only officially support one version or the other, but not both at the same time. If both versions resolve to a page (HTTP status 200) then it is bad. People will be linking to your pages both with www.domain.com and domain.com links. The page rank will be spread across both. Google will probably choose one version and drop the other from its index. You need to choose one version and make the other redirect 301 (page moved permanently) to the primary one.


this is a matter of preference to some people and a matter of fervorous religious discussion to others (like is kde better than gnome, vim vs emacs, etc).

regardless of your choice, the following code from a standard drupal .htaccess shows us how to redirect users to www:

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

and this is the code you need to force non-www urls:

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

Technical aspects aside and if you consider at first the end user perspective, you must have the www working AND the non-www must lead to the www page as well.

When orally exchanging a link, people tend to pronounce the non-www. Go to example dot com to check this or that.

Even if the www is implied, it is omitted in a conversation. Then at the receiver end, if the user is not IT educated, he will simply retype "example.com" and expect to see the website.

And now is the crucial part: if you use www to set up your example.com domain, then make sure that the no-www will also arrive there. Otherwise, end-users won't be pleased and they matter more to your site than a www or no-www rule. ;)

On a personal level, I use the www and the non-www redirect is directly configured in the DNS, not as a virtual host.