繁体   English   中英

IIS仅将http重定向到https

[英]IIS redirect http to https for domain only

我创建了ASP.NET Core项目,并为我的网站购买了SSL。 我在web.config中创建了一个重定向规则,将我的http重定向到https。 我的问题是我的网站上的每个链接现在都有https导致证书问题,因为其中一些链接没有ssl。 这就是我所做的:

<rewrite>
  <rules>
    <rule name="Redirect to https">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="Off" />
        <add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
        <add input="{HTTP_HOST}" negate="true" pattern="localhost" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
    </rule>
  </rules>
</rewrite>

例如,我的网站域名是www.example.com。 在我的项目上启用SSL后,我的网站现在是https://www.example.com 我在我的网站上为我的合作伙伴提供了一些链接,例如www.partner1.com。 问题是,现在我的合作伙伴链接在他们的网址中也有https,但他们的网站没有SSL证书,这意味着当我点击他们的链接时,我被重定向到https网址,因此我有一个证书错误页面。

如何设置我的域只有https,让我的合作伙伴href链接仍然使用http?

我建议你使用同样的规则:

 <rewrite>
     <rules>
     <clear /> 
       <rule name="Redirect to https" stopProcessing="true"> <match url=".*" /> 
       <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> 
       <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" /> 
     </rule> 
</rewrite> 

因为我正在使用它,我已经检查了你的情景,它的工作完美......正如你在答案中提到的那样。

我在我的网站页面上创建了一个链接,并将其设置为http://域名,这是另一个网站。 它没有改变,点击链接工作正常。 这是链接代码:

 <a target="_blank" href="http:// www.jwoodmaker.com/">Test</a>

因为我已经发送给你链接,其中包含完整的详细信息。 这个链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM