Forum Moderators: open
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
If Request.Url.AbsoluteUri.ToLower.StartsWith("http://www") Then
Dim newUrl As String = Request.Url.AbsoluteUri.ToLower.Replace("http://www", "http://")
Response.Status = "301 Moved Permanently"
Response.AddHeader("location", newURL)
End If
End Sub
With IIS7 rewrite module you can add the following to your web.config file:
<rule name="Redirect to non WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.example.com$" />
</conditions>
<action type="Redirect" url="http://example.com/{R:0}" redirectType="Permanent" />
</rule>
Or use something like urlrewriter.net
I'm using IIS 6 is there a way to do that there, or possibly in dns manager?
Edit: I forgot to add, the code I posted will also work in a master page, but I prefer using Global.asax for this.