Menu

Want to work with us? We're on the lookout for digital experts.

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.

This site uses essential cookies for parts of the site to operate and have already been set. Find out more about how we use cookies and how you may delete them. You may delete cookies, but parts of the site will not work.