【问题标题】:force website http:// to https://www asp.net强制网站 http:// 到 https://www asp.net
【发布时间】:2015-06-07 17:20:11
【问题描述】:

我想为我的域将非 www 和非 https 的 URL 重定向到 https://www,我实际上在 web.config 中有以下内容,可以将非 https 重定向到 https,但仍然允许访问 domain.com没有www,

<rewrite>
  <rules>
    <clear />
    <rule name="Default to root" stopProcessing="true">
      <match url="(.*)default.aspx" />
      <action type="Redirect" url="{R:1}" />
    </rule>
    <rule name="Redirect to https" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

我有共享主机..

【问题讨论】:

  • www 对你来说是必需的吗?
  • 是搜索引擎优化所必需的。 .. .
  • 您需要添加第三条规则来分析主机名头和重定向。
  • @LexLi 在第三个 rool 上收到错误消息 此网页有重定向循环
  • 发布您的第三条规则。

标签: asp.net web


【解决方案1】:

这是一个运行代码

<rewrite>
  <rules>
    <clear />
    <rule name="Default to root" stopProcessing="true">
      <match url="(.*)default.aspx" />
      <action type="Redirect" url="{R:1}" />
    </rule>
    <rule name="Redirect to https" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
    </rule>
      <rule name="Add www" stopProcessing="true">
      <match url="(.*)" ignoreCase="true" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^mydomain\.com$" />
      </conditions>
      <action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

谢谢@lexLi

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    • 2011-03-07
    • 2011-06-11
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多