1、首先去官网下载urlrewrite的包(urlrewrite-3.2.0.jar),加入到项目中;
2、在web.xml中加入以下配置:
<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>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<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>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<url-pattern>/*</url-pattern>对所有路径进行过滤;
3、在配置urlrewrite.xml:
<rule>
<!--
<note>
http://www.yifutop.com/itemList/0_0_0_0_1.html
http://www.yifutop.com/itemList.do?cid=0&sortStr=0&pirceMin=0&pirceMax=0&pageno=1
</note>
-->
<rule>
<from>/itemList/([0-9]+)_([0-9]+)_([0-9]+)_([0-9]+)_([0-9]+).html</from>
<to>/itemList.do?cid=$1&sortStr=$2&pirceMin=$3&pirceMax=$4&pageno=$5</to>
</rule>
</rule>
<!--
<note>
http://www.yifutop.com/itemList/0_0_0_0_1.html
http://www.yifutop.com/itemList.do?cid=0&sortStr=0&pirceMin=0&pirceMax=0&pageno=1
</note>
-->
<rule>
<from>/itemList/([0-9]+)_([0-9]+)_([0-9]+)_([0-9]+)_([0-9]+).html</from>
<to>/itemList.do?cid=$1&sortStr=$2&pirceMin=$3&pirceMax=$4&pageno=$5</to>
</rule>
</rule>
<rule>
<rule>
<from>/home.html</from>
<to>/home.do</to>
</rule>
</rule>
<rule>
<from>/home.html</from>
<to>/home.do</to>
</rule>
</rule>
这就是一个简单的URL转发,把home.html转到home.do链接;
这是个带有参数的转发,可以看到注释部分用户访问的链接和实际链接;
4、在你的页面就可以直接写这种.html的链接地址来对你的网站进行伪静态了
转载于:https://blog.51cto.com/2197028/1068117