Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Redirect domain.com requests to www.domain.com

Make sure you have mod_redirect in server.modules, then add this to your lighttpd.conf:

$HTTP["host"] =~ "^domain\.com$" {
  url.redirect = (
    "^/(.*)" => "http://www.domain.com/$1",
    ""       => "http://www.domain.com/"
  )
}


I wasn't able to come up with a way to do it in a single rule. It seems that only "" (not even "(.*)") will match the root request.

How to flush the local DNS cache on Mac OS X

If you want to add a virtualhost on your Mac OS X box without having to wait around for ages, then the easiest way to do so is to shove a line into /etc/hosts and flush the dnscache. Here's a friendly bash function to throw into your .bashrc:

function edithosts {
	if [ -x "`which $EDITOR`" ] || [ -x "`which $1`" ]
	then
		if [ -x "`which $EDITOR`" ]
		then
			export TEMP_EDIT="`which $EDITOR`"
		else
			export TEMP_EDIT="`which $1`"
		fi
		echo "* Using ${TEMP_EDIT} as editor"
		$TEMP_EDIT /etc/hosts && echo "* Successfully edited /etc/hosts"
		lookupd -flushcache && echo "* Flushed local DNS cache"
	else
		echo "Usage: edithosts [editor]"
		echo "(The editor is optional, and defaults to \$EDITOR)"
	fi
	unset TEMP_EDIT
}


More simply, you can just flush the DNS cache manually with:

lookupd -flushcache