<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>WARN</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
然后在WEB-INF目錄下新建urlrewrite.xml
在其中進行重寫規則的定義,它使用正則表達式來進行規則的定義
<?xml version="1.0" encoding="utf-8"?> <!-- Configuration file for UrlRewriteFilter --> 上面是我的一個簡單的測試 <rule>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.6//EN"
"
http://tuckey.org/urlrewrite/
<urlrewrite>
<rule>
<from>/test.html</from>
<to type="redirect">%{context-path}/page.html</to>
</rule>
<rule>
<from>/param/(.*)</from>
<to>/param.jsp?param=$1</to>
</rule>
</urlrewrite>
<rule>
<from>/test.html</from>
<to type="redirect">%{context-path}/page.html</to>
</rule>
是將test.html的訪問請求轉發給page.html
<from>/param/(.*)</from>
<to>/param.jsp?param=$1</to>
</rule>
將param.jsp?param=111這種請求重寫為/param/111