2017-01-16 105 views
0

我有一個IIS10服務器,並且我正在運行一個PHP應用程序。一切工作都很好我已經安裝了IIS重寫,並且它適用於規範主機名的一個規則。然而,我還有一個規則,我想限制訪問目錄中的特定圖像,除非請求來自一個特定的PHP頁面,並且我有以下規則。無論我嘗試什麼任何人都可以直接在www.mydomain.com/pics/imagename.jpg上瀏覽圖片 我在重寫模塊中使用了測試URL功能,並且我的測試通過了jpg鏈接和允許的頁面,所以我我相信這沒什麼不妥。IIS 10規則重寫不能與pho

<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> 

回答

0

居然發現了這個問題。看起來像是一個額外的正斜槓 下面的兩個小改變解決了這個問題。看起來,該條件的第一個MATCH Parth的URL意味着什麼後www.domain.com/**ThisPartOnly**

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