在IIS7中为SEO设置HTTP重定向 [英] Setting up HTTP Redirect for SEO in IIS7

查看:84
本文介绍了在IIS7中为SEO设置HTTP重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望所有对 http://mydomain.com 的请求都重定向到

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

为此,我可以使用IIS7的HTTP重定向方法吗?我尝试将HTTP重定向设置为www.mydomain.com,但这导致了永久循环.

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.

URL重写将完成这项工作,除非有人有更好的主意,否则我将使用它:

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

有什么建议吗?

推荐答案

使用IIS7可能有一种方法.诀窍在于提供防止无限循环的条件.不幸的是,我不确定该怎么做.

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.

但是您也可以在.NET代码中非常轻松地执行此操作,因为我正在执行相同的操作.我只是将其放在您的Global.asax中:

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

这篇关于在IIS7中为SEO设置HTTP重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆