被 IIS Express 指向的站点目录下大多有个web.config文件用于该网站单独设置。php
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> </system.webServer> </configuration>
首行是XML的标识,由于使用的XML,configuration包裹着的是设置。如下出现设置的XML时都会包括父级标签,这样便于知道这个设置要放在哪里。web
这个标签涉及一些安全问题相关的设置。例如:正则表达式
<system.webServer> <security> <requestFiltering allowDoubleEscaping="True"/> </security> </system.webServer>
在单入口的URL路由中,URL若是包含加号(+)这种符号时,默认IIS Express是不会交给站点程序处理的,这时会给出一个错误界面。可是咱们每每但愿给出的错误界面统一,因此修改这个设置能够让这种符号经过,再有站点程序作出处理给出页面。requestFiltering里设置allowDoubleEscaping为True就是容许这种“双转义字符”经过。api
一样在system.webServer标签下的rewrite标签能够起到重写或重定向的功能。安全
<system.webServer> <rewrite> <rules> <rule name="Entry"> <match url=".*" /> <action type="Rewrite" url="/index.php" /> </rule> </rules> </rewrite> </system.webServer>
以上是一个设置单入口的例子,rewrite标签下rules里能够放置多个rule(注意,上级是有s的)。rule有个name的属性,命名了这个rule。match标签的url是用于匹配URL的正则表达式。action标签用于真正的路由功能,type里Rewrite是重写,Redirect是重定向,url是目的URL。app
该标签能够设置可被IIS Express默认为首页也就是URL只有域名的默认页面文件。网站
<system.webServer> <defaultDocument> <files> <clear /> <add value="index.php" /> </files> </defaultDocument> </system.webServer>
这个例子里files标签里clear标签清除了系统默认的设置。查看IIS Express 的applicationhost.config文件是能够看到默认的。add标签就是把这种文件名加进默认列表中。url
在该标签下添加子元素add来添加处理器(handler),这里以启用PHP的fastCgi为例:spa
</system.webServer> <handlers accessPolicy="Read, Script"> <add name="PHP7_0_FastCGI" path="*.php" verb="GET,HEAD,POST" modules="FastCgiModule" scriptProcessor="D:\PHP-7.0.4\php-cgi.exe" resourceType="Either"/> </handlers> </system.webServer>
在applicationhost.config的location标签下设置的话全部项目(例如其余.Net)都会打开PHPfastCgi,因此在web.config里设置会比较好。code