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

查看:127
本文介绍了覆盖子站点的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天全站免登陆