Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

Simple question : should we use www in front of the url address or not... some site said we should and some said exacly the opposite...

If no www in front of the site should be use, what is the htaccess code should i used to rewrite the url and keep google happy ?

share|improve this question

migrated from stackoverflow.com Dec 10 '09 at 21:34

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Michael Hampton, sysadmin1138 Oct 11 '12 at 14:20

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
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 '09 at 21:31
14  
It's silly that the abbreviation for a 3-syllable phrase "world wide web" is pronounced with 9 syllables. –  Joe Koberg Dec 10 '09 at 21:33

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
</VirtualHost>

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.

share|improve this answer
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 '09 at 21:32
1  
You don't need the RedirectMatch; a plain Redirect permanent / http://example.com/ does the same thing. –  bobince Dec 14 '09 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 '12 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 '12 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.)

share|improve this answer

There's no good reason not to provide both.

share|improve this answer
3  
content duplication and link-juice fragmentation used to be 2 reasons –  cherouvim Dec 10 '09 at 21:33
    
Heads up about this situation: stackoverflow.com/questions/570148/… –  micahwittman Dec 10 '09 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. –  Richard Slater Dec 10 '09 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.

share|improve this answer

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]
share|improve this answer

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.

share|improve this answer