IIS 8.5 Url重写问题-重定向位置包括IP地址



我创建了一个URL重写规则,根据http://madskristensen.net/post/url-rewrite-and-the-www-subdomain

以下是直接来自我的web.config的规则:

<rewrite>
  <rules>
    <rule name="Remove WWW" patternSyntax="Wildcard" stopProcessing="true">
      <match url="*" />
      <conditions>
        <add input="{CACHE_URL}" pattern="*://www.*" />
      </conditions>
      <action type="Redirect" url="{C:1}://{C:2}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

当我尝试打开www.mydomain.com时,FireFox会给我一条"内容损坏错误"的消息。如果我尝试在Chrome中打开它,什么也不会发生。

以下是通过Fiddler的响应标头:

HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Location: http://example.com:80:123.123.123.123/
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
Date: Mon, 07 Dec 2015 18:20:53 GMT
Content-Length: 167

响应主体:

<head>
  <title>Document Moved</title>
</head>
<body>
  <h1>Object Moved</h1>This document may be found <a HREF="http://example.com:80:123.123.123.123/">here</a>
</body>

请注意端口和IP地址是如何包含在位置中的。(我已将服务器的IP地址替换为123.123.123.123)

这是造成问题的原因吗?如果是,为什么包含此信息,以及如何删除它?

安装URL重写后,我重新启动了IIS。

不是真正的解决方案,但我的解决方法。。。

我的站点设置为需要SSL,所以我不需要为这两种协议删除WWW。

我更新了我的规则如下:

<rule name="Remove WWW and Redirect to HTTPS" enabled="true" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^(www.)(.*)$" />
  </conditions>
  <action type="Redirect" url="https://{C:2}/{R:1}" />
</rule>

最新更新