专注于互联网--专注于架构

最新标签
网站地图
文章索引
Rss订阅

首页 »Java教程 » urlrewriter:urlrewriter的使用以及出现的问题 »正文

urlrewriter:urlrewriter的使用以及出现的问题

来源: 发布时间:星期四, 2009年2月12日 浏览:202次 评论:0


最近开始在用urlrewriter 记录下使用情况以及出现各种问题

首先要明确是为什么要使用url:主要考虑seo以及用户体验如何讲呢如果你页面上全是.do链接然后form也使用post用户不能将网页添加到收藏夹同时你网页也不能被搜索引擎发现其实这个才是最主要当然你经过重写url也屏蔽你后台业务逻辑

其实使用是很简单在你web应用中使用url重写其实经过很简单配置就可以实现

首先去http://tuckey.org/urlrewrite/ 下载urlrewritefilter-3.1.0.zip

我使用是beta版 版本应该没多大问题

其实里面只有两个文件个是urlrewrite-3.1.0.jar你在使用时候只要将这个jar文件放到你path中就可以使用urlrewriterl

另外个配置文件urlrewrite.xml如下

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.1//EN"
"http://tuckey.org/res/dtds/urlrewrite3.1.dtd">

<!--

Configuration file for UrlRewriteFilter
http://tuckey.org/urlrewrite/

-->
<urlrewrite>

<rule>
<note>
The rule means that requests to /test/status/ will be redirected to /rewrite-status
the url will be rewritten.
</note>
<from>/test/status/</from>
<to type="redirect">%{context-path}/rewrite-status</to>
</rule>


<outbound-rule>
<note>
The outbound-rule species that when response.encodeURL is called ( you are using JSTL c:url)
the url /rewrite-status will be rewritten to /test/status/.

The above rule and this outbound-rule means that end users should never see the
url /rewrite-status _disibledevent=></rule>

Redirect a directory
<rule>
<from>/some/olddir/(.*)</from>
<to type="redirect">/very/dir/$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 _disibledevent=>
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 _disibledevent=>< type="request" name="browser">moz</>
</rule>
eg, all requests will be checked against the condition and matched
request.Attribute("browser", "moz") will be called.

-->

</urlrewrite>
如果说只是用用按照上面步骤加到web应用就可以轻松使用它强大功能了其实强大还是正则表达式

在使用过程中遇到问题下次再写主要是中文url处理已经些正则表达式使用也没多少东西
0

相关文章

读者评论

发表评论

  • 昵称:
  • 内容: