简体   繁体   English

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

[英]IIS 8.5 Url Rewrite Issue - Redirect Location Includes IP Address

I create a URL Rewrite Rule to remove the WWW from incoming requests based on http://madskristensen.net/post/url-rewrite-and-the-www-subdomain 我创建了一个URL重写规则,以基于http://madskristensen.net/post/url-rewrite-and-the-www-subdomain从传入请求中删除WWW

Here is the rule straight from my web.config: 这是直接来自我的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>

When I try to open www.mydomain.com, FireFox gives me a "Corrupted Content Error" message. 当我尝试打开www.mydomain.com时,FireFox给我一个“内容损坏错误”消息。 If I try to open it in Chrome, nothing happens. 如果我尝试在Chrome中打开它,则什么也不会发生。

Here are the response headers via Fiddler: 这是通过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

Response body: 响应主体:

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

Notice how the port and IP address are included in the Location. 注意端口和IP地址如何包含在位置中。 (I have replaced the IP Address of my server with 123.123.123.123) (我用123.123.123.123替换了服务器的IP地址)

Is this causing the issue? 这是问题所在吗? If so, why is it including this information and how to I remove it? 如果是这样,为什么它包含此信息以及如何删除它?

I restarted IIS after installing URL Rewrite. 安装URL重写后,我重新启动了IIS。

Not really a solution, but my workaround... 并不是真正的解决方案,但是我的解决方法...

My site is setup to require SSL so I don't really need the benefit of removing WWW for both protocols. 我的网站设置为需要SSL,因此我并不需要从两种协议中删除WWW的好处。

I have updated my rule as follows: 我已将规则更新如下:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM