redirect - iis url 将 http 重定向到非 www https

标签 redirect iis web

我需要从

www.domain.dehttps://domain.de
-作品

http://www.domain.dehttps://domain.de
-作品

http://domain.dehttps://domain.de
- 不起作用

rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="false" />
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
      </conditions>
      <action type="Redirect" url="https://{C:1}/{R:1}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

最佳答案

我认为这对您有用,搜索模式具有可选的 www 并使用反向引用 C:2 进行重定向,该规则的条件是仅针对非 https 运行。

这是模式:

"^(www\.)?(.*)$"

在哪里:
{C:0} - www.domain.de
{C:1} - www.
{C:2} - domain.de

这是完整的规则:
  <rewrite>
    <rules>
      <rule name="SecureRedirect" stopProcessing="true">
        <match url="^(.*)$" />
        <conditions>
          <add input="{HTTPS}" pattern="off" />
          <add input="{HTTP_HOST}" pattern="^(www\.)?(.*)$" />
        </conditions>
        <action type="Redirect" url="https://{C:2}" redirectType="Permanent" />
      </rule>
    </rules>
  </rewrite>

关于redirect - iis url 将 http 重定向到非 www https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17110411/

相关文章:

html - 如何在 HTML 中提供指向 https 网站的超链接?

php - Laravel 5 正在将 http 重定向到 https 吗?如何禁用它?

php - 登录后Opencart登录到上一个查看的页面?

c# - iis 仅返回 Entity Framework 响应中的第一个对象

html - 使用 div 标签和 CSS 创建布局

html - 一个编辑 html/css 网站的程序?

python - 有没有一种简单的方法可以在 python 中请求 URL 而不是遵循重定向?

ruby-on-rails - Nginx 上的 SSL 导致重定向循环

asp.net - 我可以在 IIS 上部署 Azure 项目吗?

c# - StreamWriter 在行尾添加额外的\r