2017-03-10 133 views
0

我有一個網站,最近從http感動://到https://問題以https://非www重新定向到https:// WWW

該網站是建立與MVC託管在IIS7上,我知道我應該有4個綁定。

主要原因之一:
https://www.example.com(端口:443 - IP地址:*)

和3人全部到301再直接到以上。

http://www.example.com - (port:80 - ip address: * -re-direct works) 
    http://example.com - (port:80 - ip address: * -re-direct works) 
    https://example.com - (port:443 - ip address: * -re-direct does not work) 

試圖解決爲什麼底部失敗的網站無法到達。服務器DNS地址找不到。

下面是代碼我使用的重新定向HTTP到HTTPS

  // The base only redirects GET, but we added HEAD as well. This avoids exceptions for bots crawling using HEAD. 
      // The other requests will throw an exception to ensure the correct verbs are used. 
      // We fall back to the base method as the mvc exceptions are marked as internal. 

      if (!String.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase) 
       && !String.Equals(filterContext.HttpContext.Request.HttpMethod, "HEAD", StringComparison.OrdinalIgnoreCase)) 
      { 
       base.HandleNonHttpsRequest(filterContext); 
      } 

      // Redirect to HTTPS version of page 
      // We updated this to redirect using 301 (permanent) instead of 302 (temporary). 
      string url = "https://" + filterContext.HttpContext.Request.Url.Host + filterContext.HttpContext.Request.RawUrl; 

      filterContext.Result = new RedirectResult(url, true); 

任何想法是怎麼回事錯在這裏與底部結合?嘗試在Google網站站長Search Console上設置第4個媒體資源,並且顯然不能由於DNS失敗。

任何幫助都非常感謝。乾杯

回答

0

的問題是對我們的域名提供商的DNS。

0

最好在網絡服務器級而不是應用程序代碼上做這種事情。 對於IIS,您需要通過添加重寫規則來更改文件Web.config。 我無法測試,但你應該增加類似的東西:

<rewrite> 
    <rules> 
    <rule name="Redirect to www" patternSyntax="Wildcard" stopProcessing="true">    
     <match url="*" /> 
     <conditions> 
     <add input="{HTTP_HOST}" pattern="example.com" /> 
     </conditions> 
     <action type="Redirect" url="http://www.example.com/{R:0}" /> 
    </rule> 

    <rule name="HTTP Redirect to HTTPS" enabled="true" stopProcessing="true"> 
     <match url="(.*)" ignoreCase="false" /> 
     <conditions> 
     <add input="{HTTPS}" pattern="off" /> 
     </conditions> 
     <action type="Redirect" url="https://www.example.com/{R:1}" appendQueryString="true" redirectType="Permanent" /> 
    </rule> 
    </rules> 

+0

嗨,謝謝你的回覆。不幸的是,也沒有那種喜悅。 我擔心綁定或GoDaddy級別有問題。 我覺得奇怪的是 的http://非www到https:// WWW工作正常 但 https://開頭非www到https:// WWW沒有。 即使沒有重新指導,我也無法獲取https://非www的流量來完成所有工作:( – Johnathan

+0

)您是否嘗試過[response](http://stackoverflow.com/questions/38883207/url -rewrite-Web的配置-HTTPS的和WWW)? – Camille

相關問題