重定向安全域是否需要两个域上的 ssl 证书?

Viv*_*cer 2 https redirect web-config azure

我在 Microsoft Azure 上托管一个网站,需要添加从旧域 (domain1.com) 到新域 (www.domain2.com) 的重定向。然而,我遇到的问题是重定向在不安全的网址上工作正常:

http://domain1.com -> https://www.domain2.com

http://www.domain1.com -> https://www.domain2.com

但是它不能在安全网址上正常工作:

https://domain1.com -> https://www.domain2.com

https://www.domain1.com -> https://www.domain2.com

发生的情况是我收到证书警告,即给定的证书对此域无效。如果我接受警告,重定向到新域就可以了。

这表明一切工作正常,只是在浏览器中发生重定向之前协商了 ssl,并且因为第一个域上没有 ssl 证书,所以我收到警告。它是否正确?

我在这里缺少什么吗?有一个更好的方法吗?我是否需要两个域的 ssl 证书?

这是我的 web.config 文件,以便您可以看到我的配置:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <!-- Don't show directory listings for URLs which map to a directory. -->
    <directoryBrowse enabled="false" />
    <rewrite>
      <rules>
        <rule name="Protect files and directories from prying eyes" stopProcessing="true">
          <match url="\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$" />
          <action type="CustomResponse" statusCode="403" subStatusCode="0" statusReason="Forbidden" statusDescription="Access is forbidden." />
        </rule>

        <rule name="Force simple error message for requests for non-existent favicon.ico" stopProcessing="true">
          <match url="favicon\.ico" />
          <action type="CustomResponse" statusCode="404" subStatusCode="1" statusReason="File Not Found" statusDescription="The requested file favicon.ico was not found" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          </conditions>
        </rule>

        <!-- Rewrite URLs of the form 'x' to the form 'index.php?q=x'. -->
        <rule name="Short URLs" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
            <add input="{URL}" pattern="^/favicon.ico$" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" />
        </rule>

        <rule name="Redirect old-domain to new-domain" stopProcessing="true" enabled="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^(www.)?domain1.com$" />
          </conditions>
          <action type="Redirect" url="https://www.domain2.com/{R:0}" appendQueryString="true" redirectType="Permanent" />
        </rule>

        <rule name="WWW Rewrite" enabled="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" negate="true" pattern="^www\." />
            <add input="{HTTP_HOST}" negate="true" pattern="localhost" />
          </conditions>
          <action type="Redirect" url="https://www.domain2.com/{R:0}" appendQueryString="true" redirectType="Permanent" />
        </rule>

        <!-- Force HTTPS Starts -->
        <rule name="Force HTTPS" enabled="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          </conditions>
          <action type="Redirect" url="https://www.domain2.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
        </rule>
        <!-- Force HTTPS Ends -->

      </rules>
    </rewrite>

    <httpErrors>
      <remove statusCode="404" subStatusCode="-1" />
      <error statusCode="404" prefixLanguageFilePath="" path="/index.php" responseMode="ExecuteURL" />
    </httpErrors>

    <defaultDocument>
      <!-- Set the default document -->
      <files>
        <remove value="index.php" />
        <add value="index.php" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>
Run Code Online (Sandbox Code Playgroud)

小智 5

您将能够将非安全 URL 重定向到 HTTP/HTTPs。但是您\xe2\x80\x99无法将 HTTPS URL ( https://domain1.com ) 重定向到任何 HTTP/HTTPs ( https://www.domain2.com )但是,除非您安装了有效的 SSL 证书,否则

\n\n
http://domain1.com -> https://www.domain2.com [YES, with or without SSL]\nhttp://www.domain1.com -> https://www.domain2.com [YES, with or without SSL]\n
Run Code Online (Sandbox Code Playgroud)\n\n

和,

\n\n
https://domain1.com -> https://www.domain2.com [Required Valid SSL certificate for domain1.com]\nhttps://www.domain1.com -> https://www.domain2.com [Required Valid SSL for domain1.com]\n
Run Code Online (Sandbox Code Playgroud)\n\n

这\xe2\x80\x99就是为什么你会收到错误\xe2\x80\x98给定的证书对此域\xe2\x80\x99无效,因为你没有有效的证书。请注意,如果您希望旧 URL 重定向到新 HTTPS URL,则必须在旧域和新域上安装 SSL 证书。

\n