简体   繁体   中英

IIS 10 rule rewrite not working with pho

I have an IIS10 server and on that I am running a php application. Everything is working pretty fine I have IIS rewrite installed and it works fine for one rule which is canonical host name. However I have one more rule which I want to restrict access to specific images that are within a directory except when the request comes from only one specific php page and I have the below rule. No matter what I try Anyone can still browse the image directly on www.mydomain.com/pics/imagename.jpg I have used the test URL functionality within the rewrite module and my test passed for the jpg link and the allowed page so I'm confident there is nothing wrong with that.

<system.webServer>
    <rewrite>
        <rules>
            <clear />
            <rule name="CanonicalHostNameRule1">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{HTTP_HOST}" pattern="^www\.domain\.com$" negate="true" />
                </conditions>
                <action type="Redirect" url="http://www.domain.com/{R:1}" />
            </rule>
            <rule name="RestrictHotlinking" patternSyntax="Wildcard" stopProcessing="false">
                <match url="*/pictures/*.jpg" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{HTTP_REFERER}" pattern="http*://www.domain.com/OneAllowedPage.php*" negate="true" />
                </conditions>
                <action type="Rewrite" url="www.domain.com/img/placeholder.jpg" appendQueryString="false" />
            </rule>
        </rules>
    </rewrite>

Actually found the problem. Looks like it was an extra forward slash The two small changes below solved the problem. It appears that URL for the first MATCH Parth of the condition means what comes after www.domain.com/**ThisPartOnly**

   <match url="*pictures/*.jpg" />
   <action type="Rewrite" url="img/placeholder.jpg" ppendQueryString="false" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM