【URL重写】IIS7配置URL重写

URL Rewrite Module

 

此模块适用于IIS7、7.5、8。

微软在IIS7中添加了URL的重写模块,并且免费使用,可以导入.htaccess规则,但需要安装。

 

第一步:安装URL2.0模块

(图-1)

 

(图-2)

 

 

然后关闭当前窗口,重新打开服务和应用程序(IIS管理),即可看到,安装成功

(图-3)

 

 

第二步:配置站点(重点+难点)

1、这里要注意,单纯的配置URL规则,是不起作用的,需要添加处理程序的映射。

2、原IIS用的ISAPI配置文件,可以直接导入到URL2.0,但需要修改规则,不然不会成功(这点一定要注意,因为我就在这里折腾了好久)

 

一、配置 处理程序映射+模块

先把IIS应用程序池的托管管理道模式为集成(为了可以做第3,4步)

 

 

首先在IIS中的站点里,找到处理程序映射。双击进去

 

 

 

添加脚本映射

(路径:*.html

可执行文件%windir%Microsoft.NETFrameworkv2.0.50727aspnet_isapi.dll

名称:任意,比如Html_*)


添加通配符脚本映射

路径:*

可执行文件:C:\Windows\Microsoft.NET\Frameworkv2.0.\50727\aspnet_isapi.dll

名称:任意,比如Html_all

托管处理程序映射

路径:*.html

可执行文件:System.Web.UI.PageHandlerFactory

名称:任意 比如Html-Integrate


IIS中找到模块(双击进去)-->添加托管模块---->

名称:任意 如Html_*

类型:URLRewriter.ModuleRewrite

把 仅针对向asp.net 应用程序或托管处理程序发出请求调用 勾上

 

将应用程序池的托管管理道模式为经典,大功完成。

 

以上步骤是针对32位电脑系统所写,如果您的电脑是64位系统,需要再设置如下一个步骤

选择重写站点对应的应用程序连接池,高级设置,启用32位应用程序,设为true

 

上面设置完,重写成HTML肯定成功,但是II7或以上有个bug,也就是真实存在的html没有办法访问,下面我给大家提供一个可以解决的办法,也就是在webconfig里加下配置就能解决(绿底白字部分)

<system.web>

                   <globalization fileEncoding="utf-8" />

                   <customErrors mode="On" defaultRedirect="404.aspx">

                            <error statusCode="404" redirect="404.aspx" />

                   </customErrors>

                   <httpHandlers>

                            <add verb="*" path="*.html" type="System.Web.UI.PageHandlerFactory" />

                   </httpHandlers>

 

                   <compilation debug="true" targetFramework="4.0">

                            <buildProviders>

                                     <add extension=".html" type="System.Web.Compilation.PageBuildProvider" />

                            </buildProviders>

                   </compilation>

 

         </system.web>

         <system.webServer>

                   <defaultDocument>

                            <files>

                                     <clear />

                                     <add value="default.html" />

                                     <add value="default.aspx" />

                            </files>

                   </defaultDocument>

                   <handlers>

                            <add name="Html-Integrate" path="*.html" verb="*" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" preCondition="integratedMode" />

                            <add name="Html_all" path="*" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv4.0,bitness32" />

                            <add name="html_*" path="*.html" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness32" />

                   </handlers>

                   <modules>

                            <remove name="FormsAuthentication" />

                            <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" preCondition="" />

                            <remove name="UrlAuthorization" />

                            <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" preCondition="" />

                            <remove name="DefaultAuthentication" />

                            <add name="DefaultAuthentication" type="System.Web.Security.DefaultAuthenticationModule" preCondition="" />

                            <add name="html_*" type="URLRewriter.ModuleRewrite" preCondition="managedHandler" />

                   </modules>

                   <rewrite>

                            <rules>

                                     <rule name="代理单页">

                                               <match url="^daili/([0-9]+).html$" />

                                               <action type="Rewrite" url="/daili/dldetail.aspx?id={R:1}" />

                                     </rule>

                            </rules>

                   </rewrite>

         </system.webServer>

 

 

二、配置URL规则

自己现在只是略懂,所以就不说了,举几个例子

    常用的是第二个,所以一定要加^ $这两个符号

 

三、遇到的问题

1、配置过程中,出现这个错误,

无法在此应用程序的引用程序集中找到指定的类型。请确保已将程序集添加到应用程序的WEB.config的system.web/compilation中的程序集列表,仍要继续吗?

可以把下面这段代码加上

<modules>
  <remove name="FormsAuthentication" />
      <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" preCondition=""/>
      <remove name="UrlAuthorization" />
      <add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" preCondition=""/>
      <remove name="DefaultAuthentication" />
      <add name="DefaultAuthentication" type="System.Web.Security.DefaultAuthenticationModule" preCondition=""/>
</modules>

 

2、IIS7.5的配置

因为window server 2008 R2只有X64的系统,对于X64和X32没有太多的了解,所以在IIS7.5上这样配置,IIS里面的ISAPI和CGI限制,设置.net4.0和.net2.0全部允许,不区分X64和X32.(这是自己的理解,不知道有哪些影响,暂且这样吧)

 

最后

***************************************************************

考虑到需要配置多个站点的情况,为了简化操作,可以这样弄:

复制上面的红色字体部分,到web.config中对应的位置,然后在配置url规则,这样更便捷。

***************************************************************

 

参考文章:

IIS7.0设置 url重写成html(伪静态)

http://www.cnblogs.com/taizhouxiaoba/archive/2011/09/20/2182032.html

 

IIS7.5 伪静态 脚本映射 配置方法(图文详解)                      

http://www.jb51.net/article/72818.htm

 

IIS7 伪静态 web.config 配置方法【详解】

http://www.cnblogs.com/taizhouxiaoba/archive/2011/09/20/2182032.html

 

十有三博客

http://shiyousan.com/post/635646254870261696

 

无法在此应用程序的引用程序集中找到指定的类型。请确保已将程序集添加到应用程序的WEB.config的system.web/compilation中的程序集列表,仍要继续吗?

http://bbs.csdn.net/topics/390233270

 

 

分类:url重写iis配置

 

posted @ 2017-06-06 10:24  Net小付  阅读(1732)  评论(0编辑  收藏  举报