301ReidrectPages中重复记录导致的500 server error

在Umbraco平台开发一个系统时,遇到一个问题,报错500 server error, system is currently unable to handle this request.

按下F12键,查看发现是报 URL Rewrite module error 

在该系统目录下,确实有一个301RedirectsPages.config 文件,里面是对老系统的一些url, redirect到新系统下的新url.里面格式如下:

<rewriteMaps>
<rewriteMap name="Redirects">
<add key="/Aa" value="/BBb"/>
<add key="/Ac" value="/Bc"/>
<add key="/Ad" value="/Bd"/>
<add key="/Ae" value="/Be"/>
<add key="/Af" value="/Bf"/>
<add key="/Ag" value="/Bg"/>
<add key="/Ah" value="/Bh"/>
<add key="/Ac" value="/Bc"/>
<add key="/Ad" value="/Bd"/>
<add key="/Ai" value="/Bi"/>
<add key="/Ak" value="/Bk"/>
</rewriteMap>
</rewriteMaps>

在系统目录下的webconfig文件中,有<system.webServer>节点下,有一个rewrite节点,如下:

<system.webServer>
<rewrite>
        <rewriteMaps configSource="301RedirectsPages.config" />
      <rules>
        <rule name="Redirect to HTTPS" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="^OFF$" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
        </rule>
        <rule name="Remove trailing slash" stopProcessing="true">
          <match url="(.*)/$" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="{R:1}" />
        </rule>
        <rule name="Redirects">
          <match url=".*" />
          <conditions>
            <add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
          </conditions>
          <action type="Redirect" url="{C:1}" appendQueryString="false" />
        </rule>
      </rules>
    </rewrite>
</system.webServer>

弄了很久,都没有搞明白是哪里出现了问题。后来才发现问题出现中 301RedirectsPages.config 中,因为这个文件中存在重复记录。导致了这个问题出现

比如上面的301RedirectsPages.config文件中,

<add key="/Ac" value="/Bc"/>
<add key="/Ad" value="/Bd"/> 
这两个都重复了两次,把重复的删除。
这个问题就解决了
原文地址:https://www.cnblogs.com/wphl-27/p/7618436.html