2012-10-10 30 views
2

我目前正在從Linux(Apache)服務器遷移到Windows(IIS)。在Linux上我使用.htaccess文件來檢查HTTP_REFERER值,以確保我們的文件只正從我們的網站下載,而不是從其他網站鏈接到:檢查Windows服務器上的HTTP_REFERER

RewriteEngine on 
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?foo.com [NC] 
RewriteRule \.(dcr)$ - [NC,F,L] 

我怎樣才能做到這一點上Windows機器? (在Windows Server 2008 R2,IIS 7)

回答

1

看一看點數6在以下位置:

http://blogs.iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx

簡而言之,您需要安裝IIS URL Rewrite附加和創建規則,看起來像這樣:

<rule name="Prevent image hotlinking"> 
    <match url=".*\.(gif|jpg|png)$"/> 
    <conditions> 
    <add input="{HTTP_REFERER}" pattern="^$" negate="true" /> 
    <add input="{HTTP_REFERER}" pattern="^http://foo\.com/.*$" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="/images/say_no_to_hotlinking.jpg" /> 
</rule> 

當然你的規則可能會略有不同。使用URL重寫,您也可以採用當前的.htaccess規則並將其直接作爲新規則導入。它將根據您的目標爲您處理翻譯,但可能需要對生成的結果規則進行一些細微更改。

希望有所幫助。

+0

太好了,我想這就是我要找的。謝謝,史蒂夫。 –