A very simple program that uses SEO friendly 301 redirects to send raw domains to www.domain.tld. This is very useful when you have a site hosted behind a ELB on AWS which doesn't have a static IP and only a CNAME. The DNS RFC prevents you pointing a domain.tld to a CNAME so it can be very useful tool for your site.
The service can also be used to strip www. from a URL and uses a 301 to send you back to the raw domain.
node-wwwfier has been tested on nodejs 0.6.12+ and uses these components:
nodejs express cluster
Install and Run
Run these commands from your shell:
## Install requirements npm install express ## Install node-wwwfier git clone git://github.com/richarvey/node-wwwfier.git ## Run cd node-wwwfier node node-wwwfier.js
node-wwwfier As A Service
If you don't want to run this code yourself just point your raw domain at: 188.8.131.52
The Redirect Service is Hosted by squarecows and is a HA service.
You can use curl to send a test string and view the HTTP header you recieve back. This should show the 301 response code and the url with www prepended:
curl -I -H "HOST: squarecows.com" http://184.108.40.206 HTTP/1.1 301 Moved Permanently X-Powered-By: Express Content-Type: text/html Location: http://www.squarecows.com/ Connection: Keep-Alive Date: Tue, 10 Apr 2012 13:36:27 GMT
If you rewuest a host that already has www. prepended the response will look like the following:
curl -I -H "HOST: www.squarecows.com" http://220.127.116.11 HTTP/1.1 301 Moved Permanently X-Powered-By: Express Content-Type: text/html Location: http://squarecows.com/ Connection: keep-alive
Note: Don't do something silly and put yourself in a loop!
If you request an invalid Host such as an IP address the response will look like this:
curl -I -H "HOST: 18.104.22.168" http://22.214.171.124 HTTP/1.1 400 Bad Request X-Powered-By: Express Content-Type: text/plain; charset=utf-8 Content-Length: 39 Connection: keep-alive
Testing the hosted service
curl -I -H "HOST: squarecows.com" http://126.96.36.199
Testing your local service
curl -I -H "HOST: squarecows.com" http://127.0.0.1:3000