Rewrite Rule to Rewrite All EXCEPT File Extension

此生再无相见时 提交于 2019-12-08 00:38:52

问题


I've got a rule setup to rewrite everything going into a subdirectory like so:

<rule name="Forms Directory" stopProcessing="true">
    <match url="^forms/(.*)" />
    <action type="Redirect" url="forms.htm" redirectType="Permanent" />
</rule>

However, I want to make a slight change to allow it to access an ASP file in the forms folder. So I want to keep the same rule but exclude any .asp from matching the rule. I tried the following but couldn't get it to operate as expected:

<rule name="Forms Directory" stopProcessing="true">
    <match url="^forms/(.*)[^(.asp)]" />
    <action type="Redirect" url="forms.htm" redirectType="Permanent" />
</rule>

Any help on this would be greatly appreciated!


回答1:


An additional condition that checks file extension solves this.

<rule name="Forms Directory">
    <match url="^forms/(.*)" />
    <conditions>
        <add input="{REQUEST_FILENAME}" pattern=".+\.asp$" negate="true" />
    </conditions>
    <action type="Rewrite" url="forms.htm" redirectType="Permanent" />
</rule>


来源:https://stackoverflow.com/questions/9618366/rewrite-rule-to-rewrite-all-except-file-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!