Permanent 301 redirect from http:// to http://www
Replace “yourdomain.com” with your actual domain, and name the file as global.asax
<%@ Application Language=”VB” %>
<%@ Import Namespace=”System.Diagnostics” %>
<script Language=”VB” RunAt=”server”>
Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As System.EventArgs)
Try
Dim requestedDomain As String = HttpContext.Current.Request.Url.ToString().ToLower()
If InStr(requestedDomain, “http://yourdomain.com”) Then
requestedDomain = requestedDomain.Replace(“http://yourdomain.com”, “http://www.yourdomain.com”)
Response.Clear()
Response.Status = “301 Moved Permanently”
Response.AddHeader(“Location”, requestedDomain)
Response.End()
End If
Catch ex As Exception
Response.Write(“Error in Global.asax :” & ex.Message)
End Try
End Sub
</script>