首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

tomcat服务器施用url rewrite1

2012-10-25 
tomcat服务器使用url rewrite1让tomcat服务器使用url rewrite1.????第一步:首先到这里下载:http://tuckey.

tomcat服务器使用url rewrite1
让tomcat服务器使用url rewrite1.????第一步:首先到这里下载:
http://tuckey.org/urlrewrite/urlrewritefilter-3.0.4
2. 解压urlrewritefilter-3.0.4.zip
里面包含几个文件
WEB-INF
–lib\urlrewrite-3.0.4.jar
???? –urlrewrite.xml
按照目录位置放在工程的WEB-INF文件夹中
3. 在WEB-INF/web.xml配置UrlRewriteFilter
在 <servlet-mapping> 前面加入
????? <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>
4. 在WEB-INF/urlrewrite.xml 中写入rewrite规则
加入诸如此类的正则表达规则:
Redirect one url
???????? <rule>
???????????? <from>/some/old/page.html</from>
???????????? <to type="redirect">/very/new/page.html</to>
???????? </rule>

Redirect a directory
???????? <rule>
???????????? <from>/some/olddir/(.*)</from>
???????????? <to type="redirect">/very/newdir/$1</to>
???????? </rule>

Clean a url
???????? <rule>
???????????? <from>/products/([0-9]+)</from>
???????????? <to>/products/index.jsp?product_id=$1</to>
???????? </rule>
???? eg, /products/1234 will be passed on to /products/index.jsp?product_id=1234 without the user noticing.

Browser detection
???????? <rule>
???????????? <condition name="user-agent">Mozilla/[1-4]</condition>
???????????? <from>/some/page.html</from>
???????????? <to>/some/page-for-old-browsers.html</to>
???????? </rule>
eg, will pass the request for /some/page.html on to /some/page-for-old-browsers.html only for older browsers whose user agent srtings match Mozilla/1, Mozilla/2, Mozilla/3 or Mozilla/4.

5.重启tomcat,完成




例如:
在在WEB-INF/urlrewrite.xml 中写入rewrite规则为:
<rule>
????? <from>gallery/t1.html</from>
????? <to>epg/template/gallery%2CGalleryHome.vmx</to>
</rule>

<rule>
????? <from>watch/([0-9]+).html</from>
????? <to>epg/template/play%2CWatch.vmx?actid=$1</to>
</rule>

键入:http://www.bocoo.com/CN/gallery/t1.html就进入
?????? http://www.bocoo.com/CN/ epg/template/gallery%2CGalleryHome.vmx

?????? http:// www.bocoo.com /CN/watch/108.html就进入
?????? http:// www.bocoo.com /CN/epg/template/play%2CWatch.vmx?actid=108

热点排行