tomcat urlrewrite 去掉jsessionid
在tomcat urlrewrite时,url地址栏中出现了jsessionid,这对于seo是不友好的,于是上网找了一些资料。http://tuckey.org/urlrewrite/manual/3.0/urlrewrite-conf-overview-sample.html
引用
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*
http://tuckey.org/urlrewrite/manual/3.0/guide.html
引用
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<
于是在urlrewrite.xml加入以下代码:
引用
<outbound-rule encodefirst="true">
<from>^(.*);jsessionid=.*$</from>
<to>$1</to>
</outbound-rule>
但是时灵时不灵,先记下,有时间再解决。
页:
[1]