Skip to content

Tips: redirect

Andrea Fontana edited this page May 28, 2024 · 2 revisions

This will redirect every request not ending in ".html" to the .html version.

@endpoint
void redirect(Request r, Output o)
{
	if (!r.path.endsWith("/") && !r.path.endsWith(".html"))
	{
		o.addHeader("location", r.path ~ ".html");
		o.status = 302; // 301 if redirect is permanent, of course.
	}
}

Clone this wiki locally