301 Redirect
Posted by Anders Vindberg
in Lunarmedia Blog
on the 03 Mar. 2009 (168,003 views).
I always forget this particular code and spend time finding it again and again: This is for redirecting call to the root domain in Community Server to the /forums/ folder. I usually create a blank aspx page that does the redirect - otherwise the page will load (which may be several 20-30 kb before directing). In SiteUrls_override.config you can set the "home" location name to the redirect file.
<%@ Page %>
<%@ Import Namespace="System.Web" %>
<script language="C#" runat="server">
protected override void OnInit(EventArgs e)
{
System.Web.HttpContext context = System.Web.HttpContext.Current;
context.Response.Status = "301 Moved Permanently";
context.Response.AddHeader("Location", "/forums/");
}
</script>