使用URL Rewrite实现网站伪静态

时间:2021-09-25 13:14:45

1、下载urlrewritefilter-4.0.3.jar

2、在web.xml中启用URL Rewrite filter

<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>
  </filter-mapping>

3、在webinfo路径下增加urlrewrite.xml文件,该文件定义了伪静态映射规则,基于正则表达式

<urlrewrite>
  <rule>
  <from>/userinf-(\w*).html</from>
  <to type="forward">/userinf.jsp?username=$1</to>
  </rule>
  </urlrewrite>