1、下載微軟自己提供的IIS REWRITE模塊
64位:
http://www.microsoft.com/downloads/zh-cn/details.aspx?familyid=1b8c7bd8-8824-4408-b8fc-49dc7f951a00
32位:
http://www.microsoft.com/zh-cn/download/details.aspx?id=5747
武林網之家下載://www.jb51.net/softs/479310.html
2、修改網站的web.config或用記事本制作一個web.config,記住將*txt格式改為.config 代碼如下:
<system.webServer> <rewrite> <rules> <rule name="Prevent hotlinking"> <match url="^.*/.(rar|zip|7z)$" ignoreCase="true" /> <conditions> <add input="{HTTP_REFERER}" pattern="http://www.jb51.net/.*" negate="true" /> <add input="{HTTP_REFERER}" pattern="http://wt.jb51.net/.*" negate="true" /> </conditions> <action type="Rewrite" url="/no.html" /> </rule> </rules> </rewrite> </system.webServer>
設置了只允許//www.jb51.net、http://wt.jb51.net調用網站的rar、zip類型的文件。
將以上文件上傳至網站根目錄(wwwroot)下即可 如果網站有設置偽靜態,直接將上述代碼加入原有web.config一樣可以生效
武林網之家小編注:上面的內容需要放在<configuration>里面。例如如下是完整的
<?xml version="1.0" encoding="UTF-8"?><configuration> <system.webServer> <staticContent> <mimeMap fileExtension=".*" mimeType="appliction/force-download" /> </staticContent> <httpErrors> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" prefixLanguageFilePath="" path="404.htm" responseMode="File" /> </httpErrors> <rewrite> <rules> <rule name="Prevent hotlinking"> <match url="^.*/.(rar|zip|7z)$" ignoreCase="true" /> <conditions> <add input="{HTTP_REFERER}" pattern="http://www.jb51.net/.*" negate="true" /> <add input="{HTTP_REFERER}" pattern="http://m.jb51.net/.*" negate="true" /> <add input="{HTTP_REFERER}" pattern="http://www.baidu.com/.*" negate="true" /> </conditions> <action type="Rewrite" url="/daolian.htm" /> </rule> </rules> </rewrite> </system.webServer></configuration>
為了更深入的學習,希望大家繼續看一下下面的圖文教程
主要是簡單介紹一下url重寫的配置,如果上面的規則放置位置沒問題,打開url重寫
看如下圖所示內容沒問題就說明配置文件正常,否則按照上面武林網之家給出的完整示例修改即可
配置過程中的測試
模式:^.*/.(rar|zip|7z)$
編輯條件:
{HTTP_REFERER}
與模式不匹配(才觸發條件)
模式:網址匹配(//www.jb51.net/.*
)單獨的www域名,如果更多的二級域名呢
武林網之家小編更喜歡http://.*.jb51.net/.*
測試模式可以用來檢驗一下我們的寫法是否有問題
新聞熱點
疑難解答
圖片精選