2015-04-17 106 views
0

我在.htaccess中有一些規則,我試圖在新的IIS7重寫模塊區域中實現它們。IIS 7重寫.htaccess規則的正則表達式相當於

RewriteCond %{REQUEST_FILENAME} ^.*(mp3|m4a|jpeg|jpg|gif|png|bmp|pdf|doc|docx|ppt|pptx|)$ 

RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC] 

RewriteRule . - [R=403,L] 

有誰知道我該怎麼做?

感謝

+0

這是否有道理? –

回答

1

這是令人驚訝的相似:

<rule name="BlockUnauthorized"> 
    <match url="."/> 
    <conditions> 
    <add input="{REQUEST_FILENAME}" type="Pattern" 
     pattern="^.*(mp3|m4a|jpeg|jpg|gif|png|bmp|pdf|doc|docx|ppt|pptx|)$" /> 
    <add input="{HTTP_COOKIE}" type="Pattern" 
     pattern="^.*wordpress_logged_in.*$" negate="true" ignoreCase="true" /> 
    </conditions> 
    <action type="CustomResponse" statusCode="403" 
      statusReason="You need to log in, fool!" 
      statusDescription="You need to log in, fool!" /> 
</rule> 

其中直接翻譯的規則,所以你對你的原始規則的任何問題,大概會出現在這裏了。


一個問題是REQUEST_FILENAME上的第一個模式;它以|)結束,這使得整個組是可選的。由於.*可匹配任何內容,因此相當於^.*$。也就是說,它會始終匹配任何網址。

如果你只是想匹配這些擴展名結尾的文件,你可以使用:

<match url="." isFile="true"/> 
... 
<add input="{REQUEST_FILENAME}" type="Pattern" 
    pattern="\.(mp3|m4a|jpeg|jpg|gif|png|bmp|pdf|doc|docx|ppt|pptx)$" 
    ignoreCase="true" /> 

isFile="true"標誌,將只匹配指向現有文件的URL。該模式中的\.將匹配一個點。


的更多信息: