IIS7 伪静态 web.config 配置方法

时间:2022-01-19 01:23:43

1.程序方面

只需要设置web.config 就可以了。

2.服务器需要安装:URL Rewrite

下载地址:http://www.iis.net/download/URLRewrite
Godaddy 的主机已经安装这个插件。
本地在测试的时候 请查看自己是否安装这个插件。
注意要点
1.参数用“()” 括起来 ,使用 {R:1}来获得参数
2.多个参数中间用  & 分割
3. name切记不能写一样 
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime/>
</system.web>
<system.webServer>
<rewrite>
<rules>
<!-- 实现http://localhost/1024 ==> http://localhost/store/store.aspx?id=1024 -->
<rule name="storecode">
<match url="^([1-9][0-9]*)/?$" ignoreCase="true"/>
<action type="Rewrite" url="/store/store.aspx?id={R:1}"/>
</rule>
<!-- 实现http://localhost/1024/p=1&c=1 ==> http://localhost/store/store.aspx?id=1024&p=1&c=1 -->
<rule name="storecode with param">
<match url="^([1-9][0-9]*)/([^/]+)/?$" ignoreCase="true"/>
<action type="Rewrite" url="/store/store.aspx?id={R:1}&{R:2}"/>
</rule>
<!-- 下面这些据说是从Discuz论坛里导出来的,肯定是正确的,供学习借鉴 -->
<!--
<rule name="已导入的规则 1">
<match url="^userinfo-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="userinfo.aspx?userid={R:1}"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 2">
<match url="^showforum-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="showforum.aspx?forumid={R:1}"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 3">
<match url="^showtopic-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="showtopic.aspx?topicid={R:1}"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 4">
<match url="^showforum-([0-9]+)-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="showforum.aspx?forumid={R:1}&page=

{R:2}" appendQueryString="false" />
</rule>
<rule name="已导入的规则 5">
<match url="^showtopic-([0-9]+)-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="showtopic.aspx?topicid={R:1}&page=

{R:2}" appendQueryString="false" />
</rule>
<rule name="已导入的规则 6">
<match url="^archiver/showforum-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="archiver/showforum.aspx?forumid={R:1}"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 7">
<match url="^archiver/showtopic-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="archiver/showtopic.aspx?topicid={R:1}"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 8">
<match url="^archiver/showtopic-([0-9]+)-([0-9]+)\.html$"

ignoreCase="false" />
<action type="Rewrite" url="archiver/showtopic.aspx?topicid={R:1}

&page={R:2}" appendQueryString="false" />
</rule>
<rule name="已导入的规则 9">
<match url="^archiver/showforum-([0-9]+)-([0-9]+)\.html$"

ignoreCase="false" />
<action type="Rewrite" url="archiver/showforum.aspx?forumid={R:1}

&page={R:2}" appendQueryString="false" />
</rule>
<rule name="已导入的规则 10">
<match url="^tools/rss-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="tools/rss.aspx?forumid={R:1}"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 11">
<match url="^tools/spacerss-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="tools/rss.aspx?uid={R:1}&type=space"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 12">
<match url="^tools/photorss-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="tools/rss.aspx?uid={R:1}&type=photo"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 13">
<match url="^space\/((\w|\s)+)((\/?))?$" ignoreCase="false" />
<action type="Rewrite" url="space/index.aspx?user={R:1}"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 14">
<match url="^space\/((\w|\s|-)+)((\/?))?\?((.*)+)$" ignoreCase="false"

/>
<action type="Rewrite" url="space/index.aspx?user={R:1}&{R:5}"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 15">
<match url="^showdebate-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="showdebate.aspx?topicid={R:1}"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 16">
<match url="^showbonus-([0-9]+)\.html$" ignoreCase="false" />
<action type="Rewrite" url="showbonus.aspx?topicid={R:1}"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 17">
<match url="^postgoods-(\d+)*.html$" ignoreCase="false" />
<action type="Rewrite" url="postgoods.aspx?categoryid={R:1}"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 18">
<match url="^showgoodslist-(\d+)(-(\d+))?.html$" ignoreCase="false" />
<action type="Rewrite" url="showgoodslist.aspx?categoryid={R:1}

&page={R:3}" appendQueryString="false" />
</rule>
<rule name="已导入的规则 19">
<match url="^showgoods-(\d+)*.html$" ignoreCase="false" />
<action type="Rewrite" url="showgoods.aspx?goodsid={R:1}"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 20">
<match url="^install((\/?))?$" ignoreCase="false" />
<action type="Rewrite" url="/install{R:1}" />
</rule>
<rule name="已导入的规则 21">
<match url="^upgrade((\/?))?$" ignoreCase="false" />
<action type="Rewrite" url="/upgrade{R:1}" />
</rule>
<rule name="已导入的规则 22">
<match url="^aspx/([0-9]+)((\/?))?$" ignoreCase="false" />
<action type="Rewrite" url="/aspx/{R:1}{R:2}" />
</rule>
<rule name="已导入的规则 23">
<match url="^archiver((\/?))?$" ignoreCase="false" />
<action type="Rewrite" url="/archiver{R:1}" />
</rule>
<rule name="已导入的规则 24">
<match url="^space((\/?))?$" ignoreCase="false" />
<action type="Rewrite" url="/space{R:1}" />
</rule>
<rule name="已导入的规则 25">
<match url="^doc((\/?))?$" ignoreCase="false" />
<action type="Rewrite" url="/doc{R:1}" />
</rule>
<rule name="已导入的规则 26">
<match url="^(([\w|\-|_])+)((\/?))?$" ignoreCase="false" />
<action type="Rewrite" url="/{R:1}/list.aspx" />
</rule>
<rule name="已导入的规则 27">
<match url="^(([\w|\-|_])+)((\/?))?\?(.)*$" ignoreCase="false" />
<action type="Rewrite" url="/{R:1}/list.aspx?{R:2}"

appendQueryString="false" />
</rule>
<rule name="已导入的规则 28">
<match url="^(([\w|\-|_])+)/([0-9]+)((\/?))?$" ignoreCase="false" />
<action type="Rewrite" url="/{R:1}/{R:3}/list.aspx" />
</rule>
<rule name="已导入的规则 29">
<match url="^(([\w|\-|_])+)/([0-9]+)((\/?))?\?(.)*$" ignoreCase="false"

/>
<action type="Rewrite" url="/{R:1}/{R:3}/list.aspx?{R:4}"

appendQueryString="false" />
</rule>
-->
</rules>
</rewrite>
</system.webServer>
</configuration>