将以下代码保存为 web.conf 放于IIS7.5下的开启rewrite的网站的根目录中:
以下代码可以禁止在 uploads、data、templets、html 四个目录中执行 php 文件,并且可以禁止访问带有类似IP地址、参数名有 port 和 host 的参数的网址。
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="uploads"> <match url="uploads/(.*).(php)$" /> <action type="Rewrite" url="/forbiden.php?s=uploads/{R:1}.{R:2}" /> </rule> <rule name="data"> <match url="data/(.*).(php)$" /> <action type="Rewrite" url="/forbiden.php?s=data/{R:1}.{R:2}" /> </rule> <rule name="templets"> <match url="templets/(.*).(php)$" /> <action type="Rewrite" url="/forbiden.php?s=templets/{R:1}.{R:2}" /> </rule> <rule name="html"> <match url="html/(.*).(php)$" /> <action type="Rewrite" url="/forbiden.php?s=html/{R:1}.{R:2}" /> </rule> <rule name="ddos"> <match url="port=|host=|[0-9]{1,3}(\.[0-9]{1,3}){3}" /> <action type="Rewrite" url="/forbiden.php?ddos={R:1}" /> </rule> </rules> </rewrite> </system.webServer> </configuration>
<完>