覆盖子站点的 IIS 重写规则? [英] Override an IIS rewrite rule for child site?

查看:21
本文介绍了覆盖子站点的 IIS 重写规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想强制所有入站连接为我的网站恢复为 HTTPS.在 StackOverflow.com 上搜索答案产生了以下代码:

I wanted to force all inbound connections to revert to HTTPS for my site. Searching StackOverflow.com for an answer yielded the following code:

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

这很好用.现在每个进入 http://mySite.com 的人都被重定向到 https://mySite.com.

This works great. Now everyone coming in to http://mySite.com is redirected to https://mySite.com.

mySite.com 有一个子应用程序,可在 mySite.com/ajax/访问.我不希望这个子应用程序的入站连接受到重写;连接到/ajax 子应用程序时,应维护用户指定的原始协议(http 或 https).我应该在这个子应用程序的 web.config 文件中放置什么来否定发生在父级的重写?

mySite.com has a sub-application which is accessed at mySite.com/ajax/ . I don't want inbound connections to this sub-application to be subject to the rewrite; The original protocol (http or https) that the user specifies should be maintained when connecting to the /ajax sub-application. What shall I place in this child application's web.config file to negate the rewrite that takes place at the parent level?

(我希望/ajax 子站点免于 https 重写的原因是因为它可以从基于 HTTP 的第三方网页访问.如果调用/ajax 的第三方页面是HTTP(不是 HTTPS),那么我想在调用时保留 HTTP 的特性.)

(The reason I want the /ajax child site to be exempt from the https rewrite is because it may be accessed from third-party HTTP-based web pages. If the third-party page that's making the call to /ajax is HTTP (not HTTPS), then I want to retain that HTTP'ness when the call is made.)

推荐答案

以下 web.config 片段应该可以满足您的需求.它会删除此应用程序的所有重写规则.

The following web.config snippet should do what you want. It removes all rewrite rules for this application.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <!-- Insert rules for this application (if any) **below** the "clear" -->
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

这篇关于覆盖子站点的 IIS 重写规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆