加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 将非www重定向到www规则导致文件问题

发布时间:2020-12-16 09:36:39 所属栏目:asp.Net 来源:网络整理
导读:我已在我的web.config中添加此规则,以将非www URL重定向到www. rule name="Redirect to WWW" stopProcessing="true" match url=".*" / conditions add input="{HTTP_HOST}" pattern="^example.com$" / /conditions action type="Redirect" url="http://www.e
我已在我的web.config中添加此规则,以将非www URL重定向到www.

<rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^example.com$" />
          </conditions>
          <action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" />
        </rule>

虽然它适用于主站点URL.就像用户键入http://example.com一样,它会重定向到http://www.example.com

但是对于某些网址来说

http://www.example.com/userfiles/abc.pdf

它重定向到

http://www.www.example.com/userfiles/abc.pdf

在这里,您可以在URL中看到2次www.

解决方法

我猜这个应该有效:

<rule name="Redirect to WWW" stopProcessing="true">
  <match url="(.*)" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^www.example.com$" negate="true" />
  </conditions>
  <action type="Redirect" url="http://www.example.com/{R:1}" />
</rule>

如果这个不能按预期工作,您可以尝试添加另一个条件:

<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />

希望这可以帮助.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读