【问题标题】:301 rewrite / redirect rule results in 500 internal server error301 重写/重定向规则导致 500 内部服务器错误
【发布时间】:2014-01-11 18:36:22
【问题描述】:

我正在尝试使用重写规则将特定页面重定向到另一个页面。但是,当我在 Web 配置中添加以下代码时,我会收到 500 内部服务器错误。

<rewrite>
      <rules>
        <clear />
        <rule name="New Rewrite" enabled="true">
          <rule name="Redirect" stopProcessing="true">
            <match url="http://www.mydomain.com/terms" />
            <action type="Redirect" url="http://www.mydomain.com/" redirectType="Permanent"/>
          </rule>
        </rule>
      </rules>
    </rewrite>

我对重定向不太了解,但是我正在做的是,假设我有一个域www.mydomain.com,如果我有一个特定的 url www.mydomain.com/terms 我需要将它重定向到主页,即@987654324 @

更新

我已经更改了给定的重写规则,仍然可以访问页面条款。第一部分将 www 添加到基于非 www 的 url 工作正常,但不确定第二条规则有什么问题。

<rewrite>
      <rules>        
        <rule name="WWW Rewrite" enabled="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" negate="true" pattern="^www\." />
          </conditions>
          <action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
        </rule>
    <rule name="news redirect" stopProcessing="true">
          <match url="/terms" ignoreCase="true"/>
          <conditions>
            <add input="{HTTP_HOST}" pattern="domain\.com$" />
          </conditions>
          <action type="Redirect" url="http://www.mydomain.com/{R:1}" />
        </rule>
      </rules>
    </rewrite>

【问题讨论】:

    标签: .htaccess iis redirect web-config http-status-code-301


    【解决方案1】:

    下载 URL 重写模块 2.1 这应该可以解决 500 错误 https://www.iis.net/downloads/microsoft/url-rewrite

    【讨论】:

      【解决方案2】:

      尝试从匹配 URL 中删除主机:

      <match url="/terms" />
      

      【讨论】:

      • 亲爱的乔恩,我这样编辑,还是一样的错误 &lt;rules&gt; &lt;rule name="301 Redirect 1" stopProcessing="true"&gt; &lt;match url="/terms" /&gt; &lt;action type="Redirect" url="http://127.0.0.1:81/" redirectType="Permanent" /&gt; &lt;/rule&gt; &lt;/rules&gt; &lt;/rewrite&gt;
      • @TBA 您似乎还嵌入了两条规则,去掉&lt;rule name="New Rewrite" enabled="true"&gt; 行和&lt;/rule&gt; 行之一
      • @TBA 不确定,不知道是否需要&lt;clear /&gt;,除此之外它看起来还不错
      • 嗨那个错误已经消失了,但是我仍然可以访问127.0.0.1:81/terms
      • 解决了,我唯一错过的是模式也应该包括 www。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-25
      相关资源
      最近更新 更多