Menu

Want to work with us? We're on the lookout for a talented Digital Project Manager.

We're hiring

301 redirect without touching IIS (VB.NET)

Web Bureau


10 October 2011 by Web Bureau

Just a method of doing a 301 redirect from non-www to www I came across rather than doing it through IIS
http://www.barrywise.com/2008/10/seo-canonical-urls-and-301-redirects-in-windows-iis-6-iis-7/


        Try
            Dim requestedDomain As String = HttpContext.Current.Request.Url.ToString().ToLower()

            If InStr(requestedDomain, "http://thewebbureau.com") Then

                requestedDomain = requestedDomain.Replace("http://thewebbureau.com", "http://www.thewebbureau.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

Grow your businessStart a project with us today.