URLRewiter使用

使用URLRewriter(URLRewriter.dll)重写URL,至于URLRewriter就不详细介绍了,简单介绍,它是微软开源的url重写组件,

 

第一步:得到URLRewriter.dll文件,将其copy到bin下,

第二步:

配置web.config

具体配置为:

<?xml version="1.0" encoding="UTF-8"?>



<configuration>



  <!--url重写 section配置-->



  <configSections>



    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />



  </configSections>



 



  <system.web>



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



      <assemblies>



        <add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />



        <add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />



        <add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />



        <add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />



      </assemblies>



      <!-- 加上此节点,保证原本就是.html类型的文件能正常访问 -->



      <buildProviders>



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



      </buildProviders>



    </compilation>



    <!--url重写 模块配置-->



    <httpHandlers>



      <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />



      <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />



    </httpHandlers>



 



    <httpModules>



      <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />



    </httpModules>



  </system.web>



  <!--url重写 Rules配置-->



  <RewriterConfig>



    <Rules>



      <!--重写按年查询地址-->



      <!--RewriterRule>



        <LookFor>~/content_list_year,(d{1,9}),(d{1,9}),(d{4}).aspx</LookFor>



        <SendTo><![CDATA[~/Test.aspx?bigtypeid=$1&smalltypeid=$2&postyear=$3]]></SendTo>



      </RewriterRule-->



      <!--RewriterRule>



        <LookFor>~/comment,(d{1,9}).aspx</LookFor>



        <SendTo><![CDATA[~/comment.aspx?PostID=$1]]></SendTo>



      </RewriterRule>



 



      <RewriterRule>



        <LookFor>http://(\w+).abc.com/</LookFor>



        <SendTo>~/Defa.aspx?id=$1</SendTo>



      </RewriterRule>



 



      <RewriterRule>



        <LookFor>~/web/new/type/(.[0-9]*)\.html</LookFor>



        <SendTo>~/web/new.aspx?id=$1</SendTo>



      </RewriterRule>



 



      <RewriterRule>



        <LookFor>~/web/index.html</LookFor>



        <SendTo>~/web/index.aspx</SendTo>



      </RewriterRule-->



      <!--RewriterRule>



                                     <LookFor>~/1.aspx</LookFor>



                                     <SendTo>~/Search/Search_Sell.aspx?id=$1</SendTo>



                            </RewriterRule>



                            <RewriterRule>



                                     <LookFor>~/Sell/Search_Sell.aspx</LookFor>



                                     <SendTo>~/Search/Search_Sell.aspx</SendTo>



                            </RewriterRule>



                            <RewriterRule>



                                     <LookFor>~/Buy/(.[0-9]*).html</LookFor>



                                     <SendTo>~/Search/Search_Buy.aspx?id=$1</SendTo>



                            </RewriterRule>



                            <RewriterRule>



                                     <LookFor>~/Buys/(.[0-9]*).html</LookFor>



                                     <SendTo>~/Buys/Show.aspx?id=$1</SendTo>



                            </RewriterRule-->



      <RewriterRule>



        <LookFor>~/Sell/(.[0-9]*).aspx</LookFor>



        <SendTo>~/Search/Search_Sell.aspx?id=$1</SendTo>



      </RewriterRule>



    </Rules>



  </RewriterConfig>



</configuration>

 

Dubug版,Release版,iis部署都可以看到效果

你可能感兴趣的:(url)