zoukankan      html  css  js  c++  java
  • 用Intelligencia.UrlRewriter实现URL重写

     利用Open Source Intelligencia.UrlRewriter实现重写url
          实现效果如下:
      ~/video 到 ~/*.aspx(或者~/tags/*.aspx)
         ~/a.htm(或者自定义的扩展名) 到 ~/a.aspx
         ~/class/(.+)   到  ~/Class/Default.aspx?classid=$1
         等效果

        方法如下:
      (1)下载Intelligencia.UrlRewriter.dll文件
      (2)将Intelligencia.UrlRewriter.dll引用到你的website程序中
      (3)配置webconfig
         1)添加 Configuration section handler:
    <configSections>
      <section
       name="rewriter"
       requirePermission="false"
       type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
     </configSections>


         2)添加 UrlRewriter mapper HttpModule:
    <system.web>
      <httpModules>
       <add
        type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"
        name="UrlRewriter" />
      </httpModules>
     </system.web>
        3)添加 重写规则到 web.config的configuration结点中,如下
    <rewriter>
    <rewrite url="/tags/(.+)" to="/tagcloud.aspx?tag=$1" /> 
     </rewriter>
    整个web.config文件

     1<?xml version="1.0"?>
     2<configuration>
     3    <configSections>
     4        <section
     5            name="rewriter"
     6            requirePermission="false"
     7            type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
     8    </configSections>
     9    <appSettings/>
    10    <connectionStrings/>
    11    <system.web>
    12        <httpModules>
    13            <add
    14                type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"
    15                name="UrlRewriter" />
    16        </httpModules>
    17
    18    
    19        <compilation debug="true"/>
    20        
    21        <authentication mode="Windows"/>
    22
    23    </system.web>
    24    
    25    <rewriter>        
    26        <rewrite url="~/tags/(.+)" to="~/tag/tagcloud.aspx?tag=$1" />
    27        <rewrite url="~/video" to="~/Class/Default.aspx" />
    28        <rewrite url="~/class/(.+)" to="~/Class/Default.aspx?classid=$1" />
    29
    30        <rewrite url="~/test_([a-zA-Z]+).aspx$" to="~/Show.aspx?Code=$1" processing="stop" />
    31        <rewrite url="~/test_([a-zA-Z]+).html$" to="~/Show.aspx?Code=$1" processing="stop" />
    32    </rewriter>
    33    
    34</configuration>
    35

      (4)如果需要重写为htm、其它扩展名或者没有扩展名的url时,需要在IIS中设置
       设置方法如下:
            在windowXP系统中:
                 1)Open Up IIS and Navigate to the “Home Directory Tab” 
                   2)Select “Configuration” 
                   3)Click “Add” and enter “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll” in the Executable box. For the file extension, enter “.*”. Finally, make sure that “Check that file exists” is not checked. 
            在window 2003server中请参考:
            http://urlrewriter.net/index.php/support/installation/windows-server-2003/

            示例代码下载             


     

  • 相关阅读:
    Duilib 控件类html富文本绘制
    再谈如何使用Taglist?
    如何让vim自动显示函数声明-使用 echofunc.vim插件
    vim 标签页 tabnew 等的操作命令
    php数组操作集锦- 掌握了数组操作, 也就掌握了php
    php字符串操作集锦
    thinkphp疑难解决4
    如何保存gnome的linux的 会话?相当于windows下的休眠?
    开发thinkphp的第一步就是给Application目录(不包括其下的文件)777权限, 关闭selinux
    如何更改gnome-screenshot的默认的保存路径?
  • 原文地址:https://www.cnblogs.com/luyinghuai/p/1178687.html
Copyright © 2011-2022 走看看