Uriel Falak
Uriel Falak

Reputation: 199

When a dot exist in the middle of the URL, the rewriter works wrong

I have a project in asp net core 2.0.

I Have stablished the next Rule in the web.config:

<rewrite>
    <rules>
        <rule name="wwwroot" >
            <match url="([\S]+[.](js|css|png|gif|jpg|jpeg))" />
            <action type="Rewrite" url="wwwroot/{R:1}" logRewrittenUrl="true" />
        </rule>
    </rules>
</rewrite> 

When i acces to the url: www.foobar.com/lib/chart.js/dist/Chart.js for some reason the iis try to finde Chart.js in the path: wwwroot/lib/chart.js ignoring the last part of the url (/dist/Chart.js) when im expecting to take wwwroot/lib/chart.js/dist/Chart.js

Upvotes: 0

Views: 148

Answers (1)

Victor Leontyev
Victor Leontyev

Reputation: 8736

Try to modify your regexp like this: ([\S]+[.](js|css|png|gif|jpg|jpeg))$ it should consider file extension if they at the end of your url

EDIT

To your rule you should exclude urls starting from wwwroot

    <rule name="wwwroot" >
        <match url="([\S]+[.](js|css|png|gif|jpg|jpeg))" />
        <conditions logicalGrouping="MatchAll">
             <add input="{REQUEST_URI}" negate="true" pattern="^/wwwroot" ignoreCase="true" />
        </conditions>
        <action type="Redirect" url="wwwroot/{R:1}" logRewrittenUrl="true" />
    </rule>

Upvotes: 1

Related Questions