Setting up an HTTP redirect for SEO in IIS7

I want all requests to http://mydomain.com to be 301 redirected to http://www.mydomain.com for SEO purposes.

To do this, can I use the IIS7 HTTP redirect method? I tried to set up an HTTP redirect to www.mydomain.com, but it resulted in a constant loop.

Edit: The Rewrite url will do the job, and I'll use it in case anyone else has a better idea:

http://blogs.msdn.com/carlosag/archive/2008/09/02/IIS7UrlRewriteSEO.aspx

Any suggestions?

+1


source to share


4 answers


There is probably a way to do this using IIS7. The trick is to provide a condition to prevent an infinite loop. Unfortunately I am not sure how to do this.

But you can also do it in .NET code very easily as I am doing the same. I would just put this in my Global.asax file:



Imports System.Web.HttpContext
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
  Dim strWebsite As String = "http://www.mydomain.com"

  If Not Current.Request.Url.AbsoluteUri.StartsWith(strWebsite) Then
    Current.Response.Clear()
    Current.Response.Status = "301 Moved Permanently"
    Current.Response.AddHeader("Location", strWebsite & Current.Request.RawUrl)
    Current.Response.End()
  End If
End Sub

      

+1


source


Yup, the UrlRewrite module is the way to go here. Now, if you are in a scenario where you are not using IIS7, or cannot use the url rewrite module, you can still do it using an HTTP redirect. The trick is to use two separate virtual sites. The first site listens for the host header example.com and forwards everything to www.example.com. The second listens to www.example.com and behaves normally.



0


source


In the http redirect, make sure your redirect url is in the correct format.

Instead of a double slash after http, if you put a single slash it goes into an undefined loop.

so "http: //" is correct. "http: /" will create an undefined loop.

0


source


Create mydomain.com as a separate site and redirect it that way.

It looks like you do it like this:

http://technet.microsoft.com/en-us/library/cc732969%28WS.10%29.aspx

http://technet.microsoft.com/en-us/library/cc770393%28WS.10%29.aspx

Consider using Apache for this much easier.

-2


source







All Articles