On Fri, 13 Sep 2013 04:24:44 GMT, Luís Marques wrote:

Hi there!

I've been trying vibe.d in my spare time. If it goes well I plan to use it for serious stuff.

How would you implement domain redirection? For instance, from example.com to www.example.com?

I usually do it similar to this:

shared static this()
{
	auto redirectsettings = new HTTPServerSettings;
	redirectsettings.hostName = "example.com";
	listenHTTP(redirectsettings, &redirect);

	auto settings = new HTTPServerSettings;
	settings.hostName = "www.example.com";
	// setup a URLRouter etc. for the normal site...
	listenHTTP(settings, router);
}

void redirect(HTTPServerRequest req, HTTPServerResponse res)
{
	res.redirect("http://www.example.com" ~ req.requestURL);
}

settings and redirectsettings both use the same port and virtual host dispatch is used to route the requests appropriately. The redirectsettings.hostName field could also be left blank to handle all domains except www.example.com.