--- x/lighttpd-1.4.23/src/mod_simple_vhost.c	2009-03-31 00:16:59.000000000 +0200
+++ lighttpd-1.4.23/src/mod_simple_vhost.c	2009-10-18 17:33:54.000000000 +0200
@@ -23,6 +23,8 @@
 	buffer *docroot_cache_value;
 	buffer *docroot_cache_servername;
 
+	unsigned short strip_www;
+
 	unsigned short debug;
 } plugin_config;
 
@@ -87,6 +89,7 @@
 		{ "simple-vhost.default-host",      NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
 		{ "simple-vhost.document-root",     NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
 		{ "simple-vhost.debug",             NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },
+		{ "simple-vhost.strip-www",         NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },
 		{ NULL,                             NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
 	};
 
@@ -108,11 +111,13 @@
 		s->docroot_cache_servername = buffer_init();
 
 		s->debug = 0;
+		s->strip_www = 1;
 
 		cv[0].destination = s->server_root;
 		cv[1].destination = s->default_host;
 		cv[2].destination = s->document_root;
 		cv[3].destination = &(s->debug);
+		cv[4].destination = &(s->strip_www);
 
 
 		p->config_storage[i] = s;
@@ -149,12 +154,31 @@
 		}
 		BUFFER_APPEND_SLASH(out);
 
-		if (p->conf.document_root->used > 2 && p->conf.document_root->ptr[0] == '/') {
-			buffer_append_string_len(out, p->conf.document_root->ptr + 1, p->conf.document_root->used - 2);
+		if (p->conf.strip_www) {
+
+			int h = 0;
+
+			if (host->used > 4 && host->ptr[0] == 'w' && host->ptr[3] == '.') {
+				if (host->ptr[1] == 'w' && host->ptr[2] == 'w') {
+					h = 4;
+				}
+			}
+
+			if (NULL == (dp = strchr(host->ptr, ':'))) {
+				buffer_append_string_len(out, host->ptr + h, host->used - h - 1);
+			} else {
+				buffer_append_string_len(out, host->ptr + h, dp - host->ptr - h - 1);
+			}
+
 		} else {
-			buffer_append_string_buffer(out, p->conf.document_root);
-			BUFFER_APPEND_SLASH(out);
+
+			if (NULL == (dp = strchr(host->ptr, ':'))) {
+				buffer_append_string_buffer(out, host);
+			} else {
+				buffer_append_string_len(out, host->ptr, dp - host->ptr);
+			}
 		}
+
 	} else {
 		buffer_copy_string_buffer(out, con->conf.document_root);
 		BUFFER_APPEND_SLASH(out);
@@ -189,6 +213,7 @@
 	PATCH(docroot_cache_servername);
 
 	PATCH(debug);
+	PATCH(strip_www);
 
 	/* skip the first, the global context */
 	for (i = 1; i < srv->config_context->used; i++) {
@@ -209,7 +234,9 @@
 				PATCH(docroot_cache_servername);
 			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.default-host"))) {
 				PATCH(default_host);
-			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.document-root"))) {
+			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.strip-www"))) {
+                                PATCH(strip_www);
+                        }else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.document-root"))) {
 				PATCH(document_root);
 			} else if (buffer_is_equal_string(du->key, CONST_STR_LEN("simple-vhost.debug"))) {
 				PATCH(debug);
