首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >重定向安全域是否需要这两个域上的ssl证书?

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

Stack Overflow用户
提问于 2016-08-25 06:15:53
回答 2查看 2.1K关注 0票数 1

我在Microsoft上托管一个站点,我需要将一个重定向从旧域(domain1.com)添加到一个新域(www.domain2.com)。然而,我遇到的问题是,重定向在不安全的url上运行得很好:

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文件,您可以看到我的配置:

代码语言:javascript
复制
<?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>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-08-29 13:46:51

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

代码语言:javascript
复制
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]

和,

代码语言:javascript
复制
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]

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

票数 4
EN

Stack Overflow用户

发布于 2022-01-03 21:21:46

虽然上面的答案是正确的,但谷歌域名有一些强大的东西。它允许您在高级设置下使用HTTPS重定向,而不需要SSL证书。除了谷歌域名之外,我还没有在其他注册网站上看到过这种情况,我应该指出,他们从来都不支持TLD。假设您已经将所讨论的域注册或转移到Google域,下面是实现它的多么:

  1. 导航到Google域并单击要重定向的域
  2. 如果适用的话,打开菜单。
  3. 点击网站。
  4. 在“转发到现有网页,单击;添加一个转发地址。
  5. 在“网站URL”字段中输入URL或IP地址。
  6. 打开“高级设置”,选择永久重定向(301)或临时设置
  7. 然后,在“通过SSL转发”下,选择SSL on。
  8. 单击“向前”保存您的设置,就这样!
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39137952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档