在 IIS5 和 IIS6 时代,我们使用 URL REWRITING 可实现 URL 重写,使得 WEB 程序实现伪静态,但默认情况下只能实现 .ASPX 的伪静态,如果要实现伪静态 *.HTML 的页面,需要将 ISAPI 里面的 *.HTML 应用程序映射改为 .NET 的 ISAPI。但在 IIS 7 时代,这一切已经变得非常简单了,您在 WEB.CONFIG 中就可以管理这一切了。
可以直接在 IIS 7 里面进行添加重写规则,也可以直接在 WEB.CONFIG 中设置:
<?xml
version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to article.aspx">
<match url="^article/([0-9]+).html$" />
<action type="Rewrite" url="article.aspx?newid={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite to article.aspx">
<match url="^article/([0-9]+).html$" />
<action type="Rewrite" url="article.aspx?newid={R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
然后,访问 /article/366.html 就是 访问 /article.aspx?newid=366 的结果了,无需像以前 IIS 6 时代一样去添加 *.HTML 的 ISAPI 的应用程序映射了。(这对使用虚拟主机的站点来说可是个福音,不用再叫管理员去帮你加设置了,自己在 WEB.CONFIG 中可以设置这一切了)
前提是你得装了iisrewriter,这个软件自动添加了类似iis6里的配置