301重写/重定向规则导致500内部服务器错误

时间:2013-12-23 14:11:13

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

我正在尝试使用重写规则将特定页面重定向到另一个页面。但是,当我在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,如果我有一个特定的网址www.mydomain.com/terms,我需要将其重定向到家,那是www.mydomain.com

更新

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

<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>

2 个答案:

答案 0 :(得分:1)

尝试从匹配网址中删除主机:

<match url="/terms" />

答案 1 :(得分:-1)

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