IIS配置URL重写
一开始IIS配置伪静态,参考了
http://www.cnblogs.com/simoje/p/4764392.html
http://www.cnblogs.com/Fooo/archive/2011/09/24/2189744.html
也是各种尝试没能实现,后来我看到URLRewrite组件,最后成功实现了伪静态,下面附上配置步骤。
参考:
首先安装URLRewrite组件,下载地址,你也可以去官网下载
安装之后,打开IIS会看到URL Rewrite如图:
现在我们写一个url重写规则文件,
<ifmodule mod_rewrite.c>
RewriteEngine
RewriteRule ^index\.html$ /index.aspx [L]
</ifmodule>
这个代码块一个非常简单的功能是,index.html页面请求会访问我们的index.aspx。根据每个网站的的需要可以新增RewriteRule。文件后缀名为htaccess,保存。
双击URL Rewrite,点击“Import Rules…”如图:
选择我们刚才保存的htaccess文件 Import。这样你访问网站输入index.html,出来的就是index.aspx页面。
最后你会发现,网站的web.config文件会多出一段代码
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^index\.html$" ignoreCase="false" />
<action type="Rewrite" url="/index.aspx" />
</rule>
</rules>
</rewrite>
那我们直接在web.config配置文件中加入代码
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^index\.html$" ignoreCase="false" />
<action type="Rewrite" url="/index.aspx" />
</rule>
<rule name="Imported Rule 8" stopProcessing="true">
<match url="^default\.html$" ignoreCase="false" />
<action type="Rewrite" url="/index.aspx" />
</rule>
</rules>
</rewrite>
然后访问default.html,出来的就是index.aspx页面。那么再接下来项目加页面时,在web.config里加入代码就可以了。
版权声明:本文为scailin原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。