• urlrewrite 的使用方法


    转自:http://freeport.javaeye.com/blog/69687
    1、下载:
    下载地址为http://tuckey.org/urlrewrite/#download
    2、配置
    urlrewrite.jar包导入
    然后在web.xml配置过滤器
    Java代码 复制代码
    1.   <filter>  
    2.     <filter-name>UrlRewriteFilter</filter-name>  
    3.     <filter-class>  
    4.         org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>  
    5.     <init-param>  
    6.         <param-name>logLevel</param-name>  
    7.         <param-value>WARN</param-value>  
    8.     </init-param>  
    9. </filter>  
    10. <filter-mapping>  
    11.     <filter-name>UrlRewriteFilter</filter-name>  
    12.     <url-pattern>/*</url-pattern>  
    13. </filter-mapping>  
    14.    

    我用的是webwork
    所有在webwork的过滤器配置文件那里需要加点东西
    Java代码 复制代码
    1.  <filter-mapping>  
    2.     <filter-name>webwork</filter-name>  
    3.     <url-pattern>/*</url-pattern>  
    4.     <dispatcher>REQUEST</dispatcher>  
    5.        <dispatcher>FORWARD</dispatcher>  
    6.        <dispatcher>INCLUDE</dispatcher>  
    7. </filter-mapping>  
    8.    

    然后是在/WEB-INF/下面新建urlrewrite.xml
    内容如下:
    Java代码 复制代码
    1.   <?xml version="1.0" encoding="utf-8"?>  
    2. <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN"  
    3.         "http://tuckey.org/res/dtds/urlrewrite2.6.dtd">  
    4. <urlrewrite>  
    5.     <rule>  
    6.         <from>^/register.jsp$</from>  
    7.         <to>/register.action</to>  
    8.     </rule>  
    9. </urlrewrite>  
    10.     

    表示访问register.jsp的时候实际上访问的是register.action
    下面是达人写的,参考
    Java代码 复制代码
    1.    
    2. <rule>  
    3.         <note>homepage  blog username like http://blog.csdn.net/pigo</note>  
    4.             <from>/u/([a-zA-Z0-9]+)/?$</from>  
    5.             <to>/user/main.jsp?username=$1</to>  
    6.         </rule>  
    7.         <rule>  
    8.         <note>homepage  blog username like http://blog.csdn.net/pigo/rss.xml</note>  
    9.             <from>/u/([a-zA-Z0-9]+)/rss.xml$</from>  
    10.             <to>/user/rss.jsp?username=$1</to>  
    11.         </rule>  
    12.         <rule>  
    13.         <note> blog catgory  http://blog.csdn.net/pigo/category/42406.html</note>  
    14.             <from>/u/([a-zA-Z0-9]+)/category/([a-zA-Z0-9]+).html</from>  
    15.             <to>/user/cat.jsp?username=$1&catno=$2</to>  
    16.         </rule>  
    17.         <rule>  
    18.         <note> blog catgory rss http://blog.csdn.net/pigo/category/42406.xml</note>  
    19.             <from>/u/([a-zA-Z0-9]+)/category/([a-zA-Z0-9]+).xml</from>  
    20.             <to>/user/catrss.jsp?username=$1&catno=$2</to>  
    21.         </rule>  
    22.          <rule>  
    23.         <note> blog photo catgory  http://blog.csdn.net/pigo/photo/42406.html</note>  
    24.             <from>/u/([a-zA-Z0-9]+)/photo/([a-zA-Z0-9]+).html</from>  
    25.             <to>/user/photo.jsp?username=$1&catno=$2</to>  
    26.         </rule>  
    27.         <rule>  
    28.         <note>blog issue http://blog.csdn.net/pigo/archive/2006/03/23/783904.html</note>  
    29.             <from>/u/([a-zA-Z0-9]+)/archive/([0-9]+)/([0-9]+)/([0-9]+)/([a-zA-Z0-9]+).html</from>  
    30.             <to>/user/issue.jsp?username=$1&blogno=$5</to>  
    31.         </rule>  
    32.         <rule>  
    33.         <note>blogarchive by month http://blog.csdn.net/pigo/archive/2005/08.html </note>  
    34.             <from>/u/([a-zA-Z0-9]+)/archive/([0-9]+)/([0-9]+).html</from>  
    35.             <to>/user/archivelist.jsp?username=$1&year=$2&month=$3</to>  
    36.         </rule>  
    37.         <rule>  
    38.         <note>blogapi by user http://blog.csdn.net/pigo/blogapi.html </note>  
    39.             <from>/u/([a-zA-Z0-9]+)/blogapi.html</from>  
    40.             <to>/blogapi/?username=$1</to>  
    41.         </rule>  
    42.          <rule>  
    43.         <note>blogadmin by user http://blog.csdn.net/pigo/blogadmin.html </note>  
    44.             <from>/u/([a-zA-Z0-9]+)/blogadmin.html</from>  
    45.             <to>/admin/index.jsp?username=$1</to>  
    46.         </rule> 
  • 相关阅读:
    Mono 4.0 Mac上运行asp.net mvc 5.2.3
    ASP.NET SignalR 高可用设计
    .NET Fringe 定义未来
    微软“.Net社区虚拟大会”dotnetConf2015 第二天 无处不在的Xamarin
    微软“.Net社区虚拟大会”dotnetConf2015:关键词:.NET 创新、开源、跨平台
    Mono产品生命周期
    Paket 介绍
    谷歌发布的首款基于HTTP/2和protobuf的RPC框架:GRPC
    Visual Studio 2015 CTP6 发布
    皮裤原理和运营微信公众号dotNET跨平台
  • 原文地址:https://www.cnblogs.com/cerxp/p/1170981.html
Copyright © 2020-2023  润新知