将多个IIS7重写规则(重定向)合并为一个 [英] Combine Multiple IIS7 Rewrite Rules (Redirects) Into One

查看:514
本文介绍了将多个IIS7重写规则(重定向)合并为一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iis7的URL Rewrite模块来完成以下几项工作:

I am using iis7's URL Rewrite module to accomplish several things:


  • 301重定向规则从非www到www

  • 301将规则.info重定向到.com(移至我的域名的.com版本)

  • 301从旧页面重定向规则,例如/page-name.asp到/ page-name

我已经能够将前两个合并为一个规则,第3项是它自己的规则。问题是,在请求网址的情况下会生成两个301重定向:

I have been able to combine the first two into one rule, and the 3rd item is it's own rule. The problem is that two 301 redirects are generated in a case of requesting a url like:

site.info/page-name.asp /

site.info/page-name.asp/

首先301完成:

www.site.com/page-name.asp(例如添加了www并且.info去了到.com)

www.site.com/page-name.asp (e.g. www is added and .info goes to .com)

然后第二个301就完成了:

Then a second 301 is done from that to:

www.site.com/ page-name

www.site.com/page-name

我的问题是:如何将这些组合起来,以便只发生一次301重定向而不是两次?以下是他们目前在我的web.config中的两条规则:

My question is: how can I combine these so that only ONE 301 redirect occurs instead of two? Here are the two rules as they currently sit in my web.config:

<rule name="SEO - 301 Redirect - .info to .com AND force WWW" stopProcessing="false">
    <match url="(.*)" ignoreCase="true" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^site\.info$" />
    </conditions>
    <action type="Redirect" url="{ToLower:http://www.site.com/{R:1}}" redirectType="Permanent" />
</rule>
<rule name=".aspVersion-to-friendlyvia301" stopProcessing="false">
        <match url="(.*).asp" />
        <action type="Redirect" url="{R:1}" />
</rule>


推荐答案

我好像找到了自己问题的答案。这是一个黑客攻击,但完成所有必需的URL转换(例如尾随删除斜线,非www到www,toLowerCase,删除目录的默认文档,以及任何其他必要的重定向,如页面名称更改)。

I seem to have found the answer to my own question. It is a bit of a hack but accomplishes all required url transformations (e.g. trailing slash removal, non-www to www, toLowerCase, removal of default document for directories, and any other redirects necessary such as a page name change).

我所谈论的问题实际上被称为301重定向链接,解决方案呈现得相当优雅,在这里:

The problem I was talking about is actually called "chaining of 301 redirects", and the solution is presented rather elegantly, here:

http://www.seomoz。 org / blog / what-every-seo-should-know-about-iis #chaining

这篇关于将多个IIS7重写规则(重定向)合并为一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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