1. Download urlrewrite
Http://tuckey.org/urlrewrite/
2. Put the downloaded jar to our app's/WEB-INF/lib/urlrewritefilter-4.0.3.jar
3. Add the following code in WEB-INF/web. xml
The code is as follows: |
Copy code |
<Filter> <Filter-name> UrlRewriteFilter </filter-name> <Filter-class> org. tuckey. web. filters. urlrewrite. UrlRewriteFilter </filter-class> </Filter> <Filter-mapping> <Filter-name> UrlRewriteFilter </filter-name> <Url-pattern>/* </url-pattern> <Dispatcher> REQUEST </dispatcher> <Dispatcher> FORWARD </dispatcher> </Filter-mapping> |
4. Create urlrewrite. xml in/WEB-INF/urlrewrite. xml
The urlrewrite. xml file is used to describe pseudo-static redirection rules.
The code is as follows: |
Copy code |
<? Xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE urlrewrite PUBLIC "-// tuckey.org//DTD UrlRewrite 4.0 // EN" Http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd> <Urlrewrite> <! -- Configuration without parameters --> <Rule> <Note> This rule indicates that/index.html will be redirected to/Index. jsp </Note> <From>/index.html </from> <To type = "forward">/Index. jsp </to> </Rule> <! -- Configuration with a parameter --> <Rule> <Note> This rule indicates that the/index-1.html will be redirected to/Index. jsp? P1 = 1 </Note> <From>/index-(w * pai.html </from> <To type = "forward">/Index. jsp? Id = $1 </to> </Rule> <! -- Configuration of multiple parameters --> <Rule> <Note> This rule indicates that the/index-1-1.html will be redirected to/Index. jsp? P1 = 1 & p2 = 1 </Note> <From>/index-(w *)-(w * example .html </from> <To type = "forward">/Index. jsp? P1 = $1 & amp; p2 = $2 </to> </Rule> </Urlrewrite> |
In this way, you can check the effect after restarting the container (tomcat).