Setting up HTTP Redirect for SEO in IIS7

2019-08-10 22:38发布

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

In order to do this, can I use IIS7's HTTP redirect method? I tried setting the HTTP redirect to www.mydomain.com, but this led to a permanent loop.

Edit: URL Rewrite will do the job, and I am going to use it, unless somebody else has a better idea:

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

Any suggestions?

4条回答
贪生不怕死
2楼-- · 2019-08-10 23:02

In the http redirect make sure that your redirect URL is in the right format.

Instead of double slash after http, if you put single slash it will go to indefinite loop.

ie. "http://" is correct. "http:/" will create a indefinite loop.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-08-10 23:04

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

Seems 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.

查看更多
倾城 Initia
4楼-- · 2019-08-10 23:06

There probably is a way to do this with IIS7. The trick would be in providing a condition to prevent the infinite loop. Unfortunately I'm not sure how to do that exactly.

But you can also do this in .NET code very easily as I'm doing the same thing. I'd just put this in your Global.asax:

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
查看更多
smile是对你的礼貌
5楼-- · 2019-08-10 23:07

Yup, the UrlRewrite module is the way to go here. Now, if you are in a scenario where you don't have IIS7 handy, or can't use the url rewrite module, you can still do this with HTTP redirects. The trick is to use two separate virtual sites. The first site listens for the example.com host header and forwards everything to www.example.com. The second listens for www.example.com and behaves normally.

查看更多
登录 后发表回答