www or not www. what are the best practices?

let's say, i have a domain example.com

what are the best practices regarding handling names with and without www?

1) redirect requests from www.example.com/anything to example.com/anything

2) redirect requests from example.com/anything to www.example.com/anything

I chose to use the Apache web server. Should i consider using mod_rewrite (RewriteCond / RewriteRule)?

Thanks!

7 Replies

I don't bother redirecting. Let the user use whichever they want.

@JshWright:

I don't bother redirecting. Let the user use whichever they want.

Ditto. Just have the same virtualhost answer both

I don't know if there are best practices, but my preference is always to have a subdomain present. I accept both but usually force www with a rewrite. To me it just looks consistent.

Edit: if you accept both, just remember to always set domain-level cookies. If you set a cookie for www.domain.com and the user types in domain.com, the cookies won't work.

I rewrite to www for analytics purposes.

@glg:

@JshWright:

I don't bother redirecting. Let the user use whichever they want.

Ditto. Just have the same virtualhost answer both
Actually I was told years ago that redirecting might be the proper solution to avoid content duplication penalties from search engines. So I usually redirect.

Doing this to the www or the non-www version is usually up to my clients' requests or the domain name (e.g. whichever 'sounds' better).

Definitely rewrite to whatever you prefer. Duplicate links pointing to the same content split the value of of the incoming link and as melon said, duplicate content penalty could be a problem.

Thanks, guys!

I decided to rewrite to example.com w/o www.

My config looks as follows:

 <virtualhost example.com:80="">ServerName example.com
    ServerAlias www.example.com
    DocumentRoot "/var/www/sites/example.com/current/public"
    ErrorLog "/var/log/apache2/example.com-error_log"
    CustomLog "/var/log/apache2/example.com-access_log" common
    <directory "="" var="" www="" sites="" example.com="" current="" public"="">Options All
        AllowOverride All
        Order allow,deny
        Allow from all</directory> 
    RewriteEngine On
    # Remove the www
    RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
    RewriteRule ^/(.*)$ http://example.com/$1 [L,R=301]</virtualhost> 

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct