tomcat urlrewrite 去掉jsessionid

本文介绍了一种在Tomcat服务器上通过URL重写去除URL中的JSessionID的方法,以提高搜索引擎优化效果。具体实现包括配置规则以针对特定用户代理(如Googlebot)隐藏会话ID。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在tomcat urlrewrite时,url地址栏中出现了jsessionid,这对于seo是不友好的,于是上网找了一些资料。

http://tuckey.org/urlrewrite/manual/3.0/urlrewrite-conf-overview-sample.html


[quote]
Outbound Rule 1
Outbound URL's matching ^(.*);jsessionid=.*$ will be rewritten to $1.

Given that the following condtion is met.

1. The user-agent HTTP header matches the value googlebot.*

Outbound Rule 2

Outbound URL's matching *;jsessionid=* will be rewritten to $1, after response.encodeURL() has been called.

Given that the following condtion is met.

1. The user-agent HTTP header matches the value googlebot*
[/quote]

http://tuckey.org/urlrewrite/manual/3.0/guide.html
[quote]
Hide jsessionid for requests from googlebot.


<outbound-rule>
<name>Strip URL Session ID's</name>
<note>
Strip ;jsession=XXX from urls passed through
response.encodeURL().
The characters ? and # are the only things we can use to
find out where the jsessionid ends.
The expression in 'from' below contains three capture
groups, the last two being optional.
1, everything before ;jesessionid
2, everything after ;jesessionid=XXX starting with a ?
(to get the query string) up to #
3, everything ;jesessionid=XXX and optionally ?XXX
starting with a # (to get the target)
eg,
from index.jsp;jsessionid=sss?qqq to index.jsp?qqq
from index.jsp;jsessionid=sss?qqq#ttt to index.jsp?qqq#ttt
from index.jsp;jsessionid=asdasdasdsadsadasd#dfds -
index.jsp#dfds
from u.jsp;jsessionid=wert.hg - u.jsp
from /;jsessionid=tyu - /
</note>
<condition name="user-agent">googlebot</condition>
<from>^(.*?)(?:\;jsessionid=[^\?#]*)?(\?[^#]*)?(#.*)?$</from>
<to>$1$2$3</to>
</outbound-rule<
[/quote]

于是在urlrewrite.xml加入以下代码:
[quote]<outbound-rule encodefirst="true">
<from>^(.*);jsessionid=.*$</from>
<to>$1</to>
</outbound-rule>[/quote]
但是时灵时不灵,先记下,有时间再解决。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值