A couple of days ago I signed up with Slicehost and so far I’ve been really impressed.
I’ve been using Linux for 6 or 7 years. During that time I’ve had websites hosted with a few different hosting companies, but until now I’d never had my own Linux machine (or at least slice of a machine) online somewhere that I could do anything with.
I’m going to start populating the machine soon with various websites (some moved from other hosting, a few sites Sherry and I have been working on, a webapp or two that I’m writing in Ruby on Rails), and it’s also going to be a bit of a testing ground for other development work I’m doing.
While setting everything up there were a couple of things I had to remind myself of, including working with Apache’s mod_rewrite module.
I have one domain where I own both the .com and .net. For various reasons I want to make it so that whatever people type in, they always end up at the same place. I also want the www added to the start of the domain if it’s ever missed out (I initially wanted it the other way but it looks better with the www).
This is what I was aiming for:
www.domain.net -> www.domain.net
domain.net -> www.domain.net
www.domain.com -> www.domain.net
domain.com -> www.domain.net
I got this to work by modifying my domain.net apache configuration file: /etc/apache2/sites-available/domain.net
First I setup some aliases:
ServerName domain.net
ServerAlias www.domain.net
ServerAlias domain.com
ServerAlias www.domain.com
Next I created the Rewrite rule
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.net$ [NC]
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.net$1 [L,R=301]
After saving the file and restarting apache (sudo /etc/init.d/apache2 reload), everything was being directed to www.domain.net.



December 31st, 2007 19:41
Glad to have you with us. Let us know if you need anything.