您的位置:首页 > 其它

IIS配置URL重写

2016-03-08 15:50 190 查看

IIS配置URL重写

一开始IIS配置伪静态,参考了

/article/5462432.html

/article/4757369.html

也是各种尝试没能实现,后来我看到URLRewrite组件,最后成功实现了伪静态,下面附上配置步骤。

参考:

http://www.111cn.net/sys/Windows/66641.htm

首先安装URLRewrite组件,下载地址,你也可以去官网下载

http://urlrewriter.codeplex.com/

安装之后,打开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里加入代码就可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: