2016-08-25 39 views
0

我在Microsoft Azure上托管一个站点,我需要将旧域(domain1.com)的重定向添加到新域(www.domain2.com)。但是我遇到的问题是,重定向工作正常,在不安全的网址:重定向安全域是否需要在两个域上都有SSL证书?

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> 
+0

您可以分享您的当前重定向规则吗?这些规则对安全的URL不起作用? – Shiham

回答

1

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

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] 

这就是为什么你得到错误为“定证书无效此域”,因为你还没有有效的证书。请注意,如果您希望旧网址在新的HTTPS网址上重定向,您必须在旧网域和新网域上均安装SSL证书。

+0

感谢Gunjan,我尽可能多的想要 –

+0

不客气!人们使用低估旧域SSL证书的价值,这就导致了这个问题。 –