Redirect 为什么我的url重定向命令不能正常工作?
我有一个内部网站Redirect 为什么我的url重定向命令不能正常工作?,redirect,url-rewriting,iis-7.5,Redirect,Url Rewriting,Iis 7.5,我有一个内部网站http://example/。我需要将所有流量重定向到新的内部站点(http://newexample/)以下两个子文件夹中的所有内容除外: /Admin/ /API/Test/ 以下是我尝试过的: <rewrite> <rules> <rule name="Redirect Example" enabled="true" stopProcessing="true"> <match url
http://example/
。我需要将所有流量重定向到新的内部站点(http://newexample/
)以下两个子文件夹中的所有内容除外:
/Admin/
/API/Test/
<rewrite>
<rules>
<rule name="Redirect Example" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="^Admin/.*" negate="true"/>
<add input="{REQUEST_URI}" pattern="^API/Test/.*" negate="true"/>
</conditions>
<action type="Redirect" url="http://newexample/" appendQueryString="true" redirectType="Found" />
</rule>
</rules>
</rewrite>
我遇到的问题是,它正在重定向所有内容,包括两个子文件夹中的内容。我还尝试删除了
negate
属性,该属性不会导致页面重定向。我做错了什么?您只需要在规则中做一些小更改
<rule name="Redirect Example" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="^/Admin/.*" negate="true" />
<add input="{REQUEST_URI}" pattern="^/API/Test/.*" negate="true" />
</conditions>
<action type="Redirect" url="http://newexample/" appendQueryString="true" redirectType="Found" />
</rule>
我正在发布我找到的解决方案,希望它能帮助以后的人。这一切都与
以及add
元素上的pattern
属性有关。仔细观察这些细微差别:
我改变了:
<rewrite>
<rules>
<rule name="Redirect Example" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="^Admin/.*" negate="true"/>
<add input="{REQUEST_URI}" pattern="^API/Test/.*" negate="true"/>
</conditions>
<action type="Redirect" url="http://newexample/" appendQueryString="true" redirectType="Found" />
</rule>
</rules>
</rewrite>
到
<rewrite>
<rules>
<rule name="Redirect Example" enabled="true" stopProcessing="true">
<match url="(^$)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="^Admin$" negate="true"/>
<add input="{REQUEST_URI}" pattern="^API/Test$.*" negate="true"/>
</conditions>
<action type="Redirect" url="http://newexample/" appendQueryString="true" redirectType="Found" />
</rule>
</rules>
</rewrite>