redirect-www.org

No matter whether you're for or against www., you're still goinna 301.

We're here to make the choices clear and the implementation easy.

How to Redirect with...

Web Forwarding via redirect-www.org

You can use redirect-www.org for web forwarding of www to non-www or non-www to www sites without any changes to your server's configuration. All you need to do is add a CNAME or A record to your DNS for your domain.

Let's say you point www.example.com to no.redirect-www.org. You will be telling your DNS to bring all traffic for www.example.com to our server at no.redirect-www.org. Once the traffic reaches our server, it issues a 301 redirect to whatever domain you provided, sans www (example.com in this case), and the control is back to you.

The same is true in reverse - yes.redirect-www.org will issue a redirect to any domain without a leading www to the same domain with the leading www added.

Want to get Naked?

www.example.com -> example.com

Type Host (example) Answer TTL
CNAME www.example.com no.redirect-www.org 300
CNAME www.ex.ample.com no.redirect-www.org 300

Point your DNS CNAME to no.redirect-www.org.

See it in action:

curl -v http://www.no.redirect-www.org

Or put on another layer?

example.com -> www.example.com

Type Host (example) Answer TTL
A example.com 192.241.238.7 300
CNAME ex.ample.com yes.redirect-www.org 300

Point your DNS A record to 192.241.238.7.

See it in action:

curl -v http://yes.redirect-www.org

What's this redirect-www.org all about?

First of all, we provide a free redirection service for the casual website owners who have access to their custom domain's DNS settings, but not experience with servers.

Secondly, we explain how to set up www. redirection on your own server and why you'd choose one over the other.

That is all.

To go naked or not to go naked, that is the question!

The two main arguments for no-www (meaning to forgo the www. prefix) are that it looks ugly and it's redundant.

To the point of being ugly, I originally had "to www or not to www" as the header of this section, but it just didn't look good.

To the point of redundant... when I'm on the web, I'm on the web. There's no sense in typing "www." just to remind me that I'm here - I'm plenty aware on my own. It's not like I opened up Chrome intending to eat cereal and accidentally ended up on the web. And it's not as if I can type something else to get something else. The only thing that things that have a space to type a "www." have is the web. Now even I'm becoming redundant!

The two main arguments for yes-www (meaning to ensure the www. prefix) are that bare domains can't use CNAMEs and browsers' cookie security policies work differently at different subdomain levels.

To the point of DNS CNAMEs, it's a lot easier for me to switch hosting services and keep the same CNAME than it is to switch services and keep the same IP address. It's a legitimate concern when you're scaling your site or application.

To the point of browser cookies their security policies, consider how google has so many different services you can be logged into at a time: gmail (now mail.google.com), plus.google.com, search (www.google.com), etc.

Why either or? Why should I care?

Note that "to redirect or not to redirect" is not the question. A redirect providers users with a consistent experience and also lets search engines and other content providers know which style you prefer.

In cases where you don't control the server and can't specify a redirect (such as blogger), you most likely still can use a meta redirect, which functions equivalently in for user experience and search engine optimization.

<meta http-equiv="refresh" content="0;URL='http://example.com/my-permalink/'" />

You should also always specify a canonical link to the prefered domain. This will be used by Google, Facebook, Twitter, and social content providers to attribute and accumulate likes, shares, etc.

<link rel="canonical" href="http://example.com/my-permalink/" />

How do I do my own redirects?

Nginx edit | make comment

One of the best and most popular webservers.

no-www

server {
    listen       80;
    server_name  www.example.com;
    return       301 $scheme://example.org$request_uri;
}

server {
    listen       80;
    server_name  example.com;
    ...
}

yes-www

server {
    listen       80;
    server_name  example.org;
    return       301 $scheme://www.example.org$request_uri;
}

server {
    listen       80;
    server_name  www.example.org;
    ...
}

Apache edit | make comment

Although it may not be one of the best webservers, it is one of the most popular.

no-www

example.com.conf
<VirtualHost *:80>
    ServerName www.example.com
    Redirect permanent / http://example.com/
</VirtualHost>
<VirtualHost *:80>
    ServerName example.com
    ...
</VirtualHost>
.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
.htaccess generic
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

yes-www

example.com.conf
<VirtualHost *:80>
    ServerName example.com
    Redirect permanent / http://www.example.com/
</VirtualHost>
<VirtualHost *:80>
    ServerName www.example.com
    ...
</VirtualHost>
.htaccess
RewriteEngine On
RewriteCond  %{HTTP_HOST}  example.org
RewriteRule  (.*)          http://www.example.org$1
.htaccess generic
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.(.+)$ [NC]
RewriteRule ^/(.*)$ http://www\.%{HTTP_HOST}/$1 [R=301,L]

Node.JS (ConnectJS, ExpressJS) edit | make comment

It's fairly straight-forward and inuitive to set up redirects using Node.JS with Connect and / or Express.

no-www

// nowww.js
(function () {
  'use strict';

  function nowww(request, response, next) {
    var protocol = 'http' + (request.connection.encrypted ? 's' : '') + '://'
      , host = request.headers.host
      , href
      ;

    // no www. present, nothing to do here
    if (!/^www\./i.test(host)) {
      next();
      return;
    }

    // remove www.
    host = host.replace(/^www\./i, '');
    href = protocol + host + request.url;
    response.statusCode = 301;
    response.setHeader('Location', href);
    response.write('Redirecting to ' + host + request.url + '');
    response.end();
  }

  module.exports = function () {
    nowww;
  }

  // use like so:
  // nowww = require('./nowww')
  // app.use(nowww())
}());

yes-www

// yeswww.js
(function () {
  'use strict';

  function yeswww(request, response) {
    var protocol = 'http' + (request.connection.encrypted ? 's' : '') + '://'
      , host = request.headers.host
      , href
      ;

    // www. already there, nothing to do here
    if (/^www\./i.test(host)) {
      next();
      return;
    }

    // add www.
    host = 'www.' + host;
    href = protocol + host + request.url;
    response.statusCode = 301;
    response.setHeader('Location', href);
    response.write('Redirecting to ' + host + request.url + '');
    response.end();
  }

  module.exports = function () {
    yeswww;
  }

  // use like so:
  // nowww = require('./yeswww')
  // app.use(yeswww())
}());

Other methods...  make comment 

Don't see what you're looking for here?  Add your own method (use  nginx.jade as an example) or request an example.