目前,我从Linux(阿帕奇)服务器迁移到Windows(IIS)。在Linux上我使用.htaccess文件来检查HTTP_REFERER值,以保证我们的文件只正在从我们的网站下载,而不是从其他网站链接:
I'm currently migrating from a Linux (Apache) server to Windows (IIS). On Linux I'm using a .htaccess file to check the HTTP_REFERER value, to ensure our files are only being loaded from our site, and not linked to from other sites:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?foo.com [NC]
RewriteRule .(dcr)$ - [NC,F,L]
我怎样才能做到这一点在Windows机器上? (在Windows Server 2008 R2,IIS 7)
How can I accomplish this on a Windows machine? (Windows Server 2008 R2, IIS 7)
看一看点数6在以下位置:
Have a look at point number 6 at the following location:
的http://blogs.iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx
简而言之,你需要安装 IIS URL重写添加 - 并创建一个规则,看起来是这样的:
In a nutshell, you need to install the IIS URL Rewrite add-on and create a rule that looks something like:
<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规则,并直接导入它作为一个新的规则。这将处理翻译,你虽然取决于你的目标,你可能需要进行一些小的改动,以生成所产生的规则。
Your rule may look slightly different of course. With URL Rewrite, you can also take your current .htaccess rule and import it directly as a new rule. It will handle the translation for you although depending on your objectives, you might need to make some minor changes to the resulting rules that are generated.
希望有所帮助。