Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewrite Rule to Rewrite All EXCEPT File Extension

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!

like image 814
Dexter Avatar asked Dec 03 '25 09:12

Dexter


1 Answers

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>
like image 175
Kul-Tigin Avatar answered Dec 06 '25 15:12

Kul-Tigin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!