重定向安全域是否需要在两个域上都有 ssl 证书?
Does redirecting a secure domain require an ssl certificate on both domains?
我在 Microsoft Azure 上托管一个站点,我需要添加从旧域 (domain1.com) 到新域 (www.domain2.com) 的重定向。然而,我遇到的问题是重定向在不安全的 url 上工作正常:
但是它不能在安全 url 上正常工作:
我收到证书警告,即给定的证书对该域无效。如果我接受警告,重定向到新域就好了。
这表明我一切正常,只是在浏览器中发生重定向之前协商了 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>
您将能够将不安全 URL 重定向到 HTTP/HTTPs。但是您将无法重定向 HTTPS URL (https://domain1.com) to any HTTP/HTTPs (https://www.domain2.com),除非您安装了有效的 SSL 证书。
http://domain1.com -> https://www.domain2.com [YES, with or without SSL]
http://www.domain1.com -> https://www.domain2.com [YES, with or without SSL]
而且,
https://domain1.com -> https://www.domain2.com [Required Valid SSL certificate for domain1.com]
https://www.domain1.com -> https://www.domain2.com [Required Valid SSL for domain1.com]
这就是为什么您收到错误消息“给定的证书对该域无效”的原因,因为您没有有效的证书。请注意,如果您希望旧 URLs 在新 HTTPS URLs 上重定向,则必须在旧域和新域上都安装 SSL 证书。
虽然上面的答案是正确的,但 Google 域有一些强大的功能。它允许您在高级设置下使用 HTTPS 重定向,而无需 SSL 证书。除了 Google 域之外,我还没有在其他注册商那里看到过它,我应该注意到他们不支持任何 TLD。假设您已经注册或将有问题的域转移到 Google 域,这里是 how 来实现它:
- 导航至 Google Domains 并点击进入您要重定向的域
- 打开菜单菜单(如果适用)。
- 单击网站。
- 在“转发到现有网页”下,单击;添加转发地址。
- 在“网站 URL”字段中输入 URL 或 IP 地址。
- 打开 'Advanced Settings',并可选择 select 永久重定向 (301) 或临时
- 然后,在 FORWARDING OVER SSL 下,select SSL on
- 单击“前进”以保存您的设置!
我在 Microsoft Azure 上托管一个站点,我需要添加从旧域 (domain1.com) 到新域 (www.domain2.com) 的重定向。然而,我遇到的问题是重定向在不安全的 url 上工作正常:
但是它不能在安全 url 上正常工作:
我收到证书警告,即给定的证书对该域无效。如果我接受警告,重定向到新域就好了。
这表明我一切正常,只是在浏览器中发生重定向之前协商了 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>
您将能够将不安全 URL 重定向到 HTTP/HTTPs。但是您将无法重定向 HTTPS URL (https://domain1.com) to any HTTP/HTTPs (https://www.domain2.com),除非您安装了有效的 SSL 证书。
http://domain1.com -> https://www.domain2.com [YES, with or without SSL]
http://www.domain1.com -> https://www.domain2.com [YES, with or without SSL]
而且,
https://domain1.com -> https://www.domain2.com [Required Valid SSL certificate for domain1.com]
https://www.domain1.com -> https://www.domain2.com [Required Valid SSL for domain1.com]
这就是为什么您收到错误消息“给定的证书对该域无效”的原因,因为您没有有效的证书。请注意,如果您希望旧 URLs 在新 HTTPS URLs 上重定向,则必须在旧域和新域上都安装 SSL 证书。
虽然上面的答案是正确的,但 Google 域有一些强大的功能。它允许您在高级设置下使用 HTTPS 重定向,而无需 SSL 证书。除了 Google 域之外,我还没有在其他注册商那里看到过它,我应该注意到他们不支持任何 TLD。假设您已经注册或将有问题的域转移到 Google 域,这里是 how 来实现它:
- 导航至 Google Domains 并点击进入您要重定向的域
- 打开菜单菜单(如果适用)。
- 单击网站。
- 在“转发到现有网页”下,单击;添加转发地址。
- 在“网站 URL”字段中输入 URL 或 IP 地址。
- 打开 'Advanced Settings',并可选择 select 永久重定向 (301) 或临时
- 然后,在 FORWARDING OVER SSL 下,select SSL on
- 单击“前进”以保存您的设置!