您的位置:首页 > Web前端 > HTML

超实用:IIS 7.5修改WEB.CONFIG即可实现*.HTML伪静态

2011-07-29 17:12 471 查看
在IIS5和IIS6时代,我们使用URL REWRITING可实现URL重写,使得WEB程序实现伪静态,但默认情况下只能实现.ASPX的伪静态,如果要实现伪静态*.HTML的页面,需要将ISAPI里面的*.HTML应用程序映射改为.NET的ISAPI。但在IIS 7时代,这一切已经变得非常简单了,您在WEB.CONFIG中就可以管理这一切了。 可以直接在IIS 7里面进行添加重写规则,也可以直接在WEB.CONFIG中设置:XML/HTML Code<?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> 然后,访问 /article/366.html 就是 访问/article.aspx?newid=366的结果了,无需像以前IIS 6时代一样去添加*.HTML的ISAPI的应用程序映射了,这对使用虚拟主机的站点来说可是个福音,不用再叫管理员去帮你加设置了,自己在WEB.CONFIG中可以设置这一切了 下面贴一下Rewrite规则,作用是把所有非“blog.creke.net”的内容都301重定向到“blog.creke.net”:<configuration> <system.webServer> <rewrite> <rules> <rule name="Redirect Domain" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTP_HOST}" pattern="^blog\.creke\.net$" negate="true"/> </conditions> <action type="Redirect" url="http://blog.creke.net/{R:0}" redirectType="Permanent"/> </rule> </rules> </rewrite> </system.webServer> </configuration>其实和.htaccess差不多,只不过IIS的配置是xml语法。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐