IIS 7重写web.config serverVariables指令在子文件夹中不起作用 [英] IIS 7 Rewrite web.config serverVariables directive not working in sub folder

查看:142
本文介绍了IIS 7重写web.config serverVariables指令在子文件夹中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的web.config中包含以下代码

I have the following code in my web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="IP Correction">
                    <match url="(.*)" />
                    <serverVariables>
                        <set name="REMOTE_ADDR" value="{HTTP_X-Forwarded-For}"/>
                    </serverVariables>
                    <action type="None" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

这在我的网站的根目录上非常有效,但是该规则未在任何子文件夹中触发.

This works perfectly on the root of my site, however, the rule isn't being triggered in any of the sub folders.

推荐答案

我知道了.问题出在这行代码

I figured this out. The problem was in this line of code

<action type="None" />

您必须指定重写操作

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="IP Correction">
                    <match url="(.*)" ignoreCase="true" />
                    <serverVariables>
                        <set name="REMOTE_ADDR" value="{HTTP_X-Forwarded-For}" replace="true"/>
                    </serverVariables>
                    <action type="Rewrite" url="{R:0}" appendQueryString="true" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

这篇关于IIS 7重写web.config serverVariables指令在子文件夹中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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