结合多个IIS7重写规则(重定向)组合成一个

问题描述 投票:4回答:2

我使用的IIS7的URL重写模块来完成几件事情:

  • 从非www到www 301重定向规则
  • 301重定向规则。信息以.COM(移动到我的域名.com版本)
  • 301从旧的页面重定向例如规则/page-name.asp只/页名

我已经能够在前两个组合成一个规则,第三个产品它自己的规则。问题是两个301重定向请求中像一个URL的情况下产生的:

site.info/怕个-那么.asp/

首先301做是为了:

www.site.com/page-name.asp(例如万维网,并将。信息转到.COM)

然后第二个301是从到完成:

呜呜呜.site.com/怕个-那么

我的问题是:我怎么能结合这些,使得只有一个301重定向发生,而不是两个?这里有两个规则,因为他们现在坐在我的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>
iis-7 url-rewriting
2个回答
6
投票

我似乎已经找到了答案,以我自己的问题。这是一个黑客位,但完成所有必需的网址转换(例如斜线去除,非www到www,toLowerCase,去除默认文档对于目录,以及任何其他重定向必要的,如页面名称变更)。

我是在谈论这个问题实际上被称为“301个重定向链”,并且将溶液呈现相当优雅,在这里:

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


0
投票

该解决方案从以前的评论:

1)而不是重定向的适用与其他符号重写_

2)添加新规则,将赶上网址开头_和应用重定向

<rule name="LowerCaseRule1" stopProcessing="false">
      <match url="(.*)" ignoreCase="false" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_METHOD}" pattern="GET" />
        <add input="{R:1}" pattern="[A-Z]" ignoreCase="false" />
      </conditions>
      <action type="Rewrite" url="_{ToLower:{R:1}}" />
</rule>
<rule name="RemoveTrailingSlashRule1" stopProcessing="false">
      <match url="(.*)/$" />
      <conditions  logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_METHOD}" pattern="GET" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      </conditions>
      <action type="Rewrite" url="_{R:1}" />
    </rule>
<rule name="Final redirect" stopProcessing="true">
      <match url="^(_+)(.*)" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_METHOD}" pattern="GET" />
      </conditions>
      <action type="Redirect" url="{R:2}" />
</rule>
© www.soinside.com 2019 - 2024. All rights reserved.