HTTPS从我的域名的任何HTTP网址重定向

问题描述:

我有一个TeamCity生成服务器,用于通过IIS运行的CI。我非常希望我的网域上的任何网址都被重定向到网址的HTTPS版本。HTTPS从我的域名的任何HTTP网址重定向

我跟着教程链接在这里:http://www.jppinto.com/2010/03/automatically-redirect-http-requests-to-https-on-iis7-using-url-rewrite-2-0/

<system.webServer> 
     <rewrite> 
      <rules> 
      <clear />   


    <rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
     <match url="(.*)" negate="true" /> 
     <conditions> 
        <add input="{HTTPS}" pattern="^OFF$" /> 
      </conditions> 
     <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" /> 
    </rule> 

    <rule name="Subdirectory HTTP to HTTPS redirect" enabled="true" patternSyntax="ECMAScript" stopProcessing="true"> 
      <match url="(^admin/.*)" /> 
      <conditions> 
       <add input="{HTTPS}" pattern="off" /> 
      </conditions> 
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" /> 
    </rule> 

     </rules>   
    </rewrite> 
</system.webServer> 

此外,这是我的web.config的当前版本下本教程后:

我真的不知道我做错了,因为我的域的主要网址似乎重定向到https,但许多子域名只是404,除非您明确指定HTTPS。任何帮助,将不胜感激!

尝试创建JavaScript协议重定向并将新处理程序绑定到所有HTTP-80(非安全)侦听器,其中默认错误页面和默认文档是带有Javascript重定向的静态文件。看下面的例子,包括截图(链接)。 INSECURE的默认文档也应该是index.htm

<!DOCTYPE html><html> 
<!-- This is index.htm --> 
<head><script> 
if (window.location.protocol != "https:") { 
    window.location.protocol = "https:"; 
    window.location.reload(); 
}</head></html> 

ASP重定向解决方案:
<% Response.Redirect "https://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL") %>

PHP重定向解决方案:
<?php header('HTTP/1.1 302 Found'); header('Location: https://' . $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI]); ?>

处理器配置在IIS站点:Handler config

错误页面在不安全的网站: Custom error pages

+0

我将在此期间的ASP版本上工作,如果你想要PHP的话 – NikolaTeslaX 2015-03-31 14:46:39

+0

完成后,为答案添加了ASP和PHP解决方案。他们不检查任何东西,不要问任何问题,只是重定向,简短而甜蜜。如果您使用其中之一,请相应地更改文件类型。 – NikolaTeslaX 2015-03-31 15:09:06