简体   繁体   English

IIS重写规则澄清

[英]IIS Rewrite Rule Clarification

Could someone please help me understand the difference when to use: 有人可以帮助我了解使用时的区别:

<match url="^$" /> vs. <match url=".*" />

Example: 例:

<rule name="Test" stopProcessing="true">
            <match url="^$" />
            <conditions>
              <add input="{{HTTP_HOST}}" pattern="^(.+\.)?domain\.com\.au$" />
            </conditions>
            <action type="Redirect" url="http://www.new-domain.com.au/" />
          </rule>

^$ will match empty url ^ $将匹配空网址

.* will match any url empty or not .Will not match mulitiline url's though 。*将匹配任何url为空或不匹配。虽然不会匹配多行网址

Prevent Image Hotlinking

Image Hotlinking is the use of an image from one site into a web page belonging to a second site. 图像热链接是从一个站点到属于另一个站点的网页中的图像的使用。 Unauthorized image hotlinking from your site increases bandwidth use, even though the site is not being viewed as intended. 即使未按预期查看站点,未经授权的站点图像热链接也会增加带宽使用量。 There are other concerns with image hotlinking, for example copyrights or usage of images in an inappropriate context. 图像热链接还有其他问题,例如版权或在不适当的上下文中使用图像。

With URL Rewrite Module, it is very easy to prevent image hotlinking. 使用URL重写模块,很容易防止图像热链接。 For example the following rewrite rule prevents hotlinking to all images on a web site http://ruslany.net : view plaincopy to clipboardprint? 例如,以下重写规则可防止热链接到网站http://ruslany.net上的所有图像:查看纯文本到剪贴板打印吗?

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

This rule will rewrite a request for any image file to /images/say_no_to_hotlinking.jpg only if the HTTP Referer header on the request is not empty and is not equal to the site's domain. 仅当请求上的HTTP Referer标头不为空且不等于站点域时,此规则才会将对任何图像文件的请求重写为/images/say_no_to_hotlinking.jpg。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM