ssl - URL Rewrite Force to https 除了一个域

标签 ssl https url-rewriting web-config

首先,我要说的是,经过几个小时的谷歌搜索,我找不到获得所需结果的方法。 问题是:

  1. 我的网站有 2 个域,例如:(foo.com) 和 (bar.com)
  2. 我需要将 foo.com 域重定向到 HTTPS
  3. 我需要 bar.com 保持在其 HTTP 上并且不重定向到 HTTPS

我尝试了很多规则,但没有一个能奏效。例如:

<rule name="Force HTTPS" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
        <add input="{REQUEST_URI}" negate="true" pattern="^(www.)?bar.com$$" ignoreCase="true" />
    </conditions>
    <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>

最佳答案

这应该将 foo.com 重定向到 HTTPS:

<rule name="Add WWW prefix to foo.com and use HTTPS" stopProcessing="true">
     <match url="(.*)" ignoreCase="true" />
      <conditions>
          <add input="{HTTP_HOST}" pattern="^foo\.com" />
      </conditions>
      <action type="Redirect" url="https://www.foo.com/{R:1}" redirectType="Permanent" />
 </rule>

对于 bar.com:

<rule name="Force NonHTTPS" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTPS}" pattern="on" />
    </conditions>
    <action type="Redirect" url="http://{HTTP_HOST}/{REQUEST_URI}" />
</rule>

查看第一条规则中的 stopProcessing 属性。当 foo.com 匹配时,它应该停止处理下一个规则。这将不允许触发“强制非 HTTPS”规则。

关于ssl - URL Rewrite Force to https 除了一个域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50777136/

相关文章:

ruby-on-rails - 在 RSpec Rails 中测试 HTTPS (SSL) 请求

asp.net - 使用 IIS7 URL 重写模块强制使用 HTTPS 并避免重复的 URL

bash - 使用 Bash 确定 URL 是 HTTP 还是 HTTPS

python - 由于 SSLError,urllib.request.open 无法打开 URL

ssl - 让我们与 Jitsi Meet 一起为站点加密证书

apache - 没有mod_rewrite的Apache重写?

.htaccess - 使用相对重写URL从文件夹内进行301重写

java - 移动 SSL 证书 - 现在获取 java.security.cer.CertPathValidatorException

ssl - Heroku SSL : install intermediate cert?

asp.net - 此站点无法提供安全连接 (ERR_SSL_PROTOCOL_ERROR)