根目录创建web.config文件
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ALLChange" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
这样index.php就可以省去了,但是代码中的正则 ^(.*)$ 匹配了所有点什么什么结束的url,这样我们系统中真静态文件就无法访问了,所以要在代码中过滤一下
<rule name="STATICCONTENT" stopProcessing="true">
<match url="\.(js|css|png|jpg|jpeg|gif|ico|txt)$" ignoreCase="false" />
<action type="Rewrite" url="{PATH_INFO}" appendQueryString="true" />
</rule>
网友评论