asp.net - 仅一个 URL 的 HTTP 到 HTTPS 重定向

标签 asp.net http redirect iis-7 https

想知道是否有人可以提供帮助。非常感谢!

问题:

  • blog.example.com
  • cool.example.com

    重定向到 https://www.example.com

目标:

我们试图只重定向

  • http://example.com

  • http://www.example.com

    https://www.example.com

当前代码

web.config 中的当前代码是这样的。停留在 <match url="(.*)">

以下是重写规则的其余部分。

<system.webServer>     
 <rewrite>
    <rules>
       <rule name="Redirect to https">
          <match url="(.*)" />
          <conditions>
             <add input="{SERVER_PORT}" pattern="443" negate="true" />
          </conditions>
          <action type="Redirect" url="https://www.example.com" />
       </rule>
    </rules>
 </rewrite>
<modules runAllManagedModulesForAllRequests="true"/>
<defaultDocument enabled="true">
  <files>
    <clear/>    
    <!--Remove this line or place below to deprecate-->
    <add value="default.aspx"/>
    <add value="index.html"/>
    <add value="index.php"/>
    <add value="default.html"/>
  </files>
</defaultDocument>

最佳答案

修改<match url="(.*)" />仅包含 example.comwww.example.com - 现在您正在匹配所有网址。

http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module/

关于asp.net - 仅一个 URL 的 HTTP 到 HTTPS 重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9508588/

相关文章:

asp.net - GridView 中需要两个标题行

c# - c#中php的等效代码是什么

css - 在《Professional ASP.NET 4.5 in C# and VB》一书中,为什么CSS相邻选择器定义与示例不匹配?

php - PHP 中的外部 HTTP 身份验证

php - 使用 laravel 5 发送重定向和设置 cookie

asp.net - 如何跟踪对 Linq-to-sql DataContext 的查询

c - 在本地 http 服务器上支持 keep-alive 套接字的问题

c# - 如何在 ASP.NET MVC 中将参数数组作为 GET/POST?

asp.net - 管理 ASP.NET 应用程序中的维护页面重定向

Apache 重定向和 HTTPS