【Azure 应用服务】Web.config中设置域名访问限制,IP地址限制访问特定的页面资源 (Rewrite)
原创
©著作权归作者所有:来自51CTO博客作者lulight的原创作品,请联系作者获取转载授权,否则将追究法律责任
问题描述
问题一:web app已经绑定了域名,例如是www.a.com,现在只允许使用www.a.com 访问,如果使用默认的域名xxxx.chinacloundsites.cn访问的时候,需要显示一个错误的页面该如何怎么设置呢
问题二:有一个特定的页面/admin/login/index.html只想特定的IP访问,该如何去写配置web.config呢?
以上问题都是通过配置Rewrite的规则来实现:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<rewrite>
<rules>
########## 解决问题一,根据域名进行调转 ###########
<rule name="WWW Redirect" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.a.com$" />
</conditions>
<action type="Redirect" url="http://www.a.com/{R:0}" redirectType="Permanent"
########## 解决问题二,根据IP地址调转 ###########
"special IP Rule" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REMOTE_HOST}" pattern="^192\.168\.1\.16" />
</conditions>
<action type="Redirect" url="/admin/login/index.html"
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!