我正在使用 spring MVC 并且在 jsessionid 中遇到问题,我发现如果浏览器中未启用 cookie,则会将 jsessionid 注入到 url 中,从而生成如下 url:
http://localhost/categories;jsessionid=Bsls4aQFXA5RUDcmZKV5iw?cid=13001 http://localhost/categories;jsessionid=Bsls4aQFXA5RUDcmZKV5iw?cid=13001
实际上浏览器没有问题,但是当 Google 抓取我的网站时,Google 抓取工具似乎没有 cookie:),它们以这种形式存储我网站的 url,并且我的网站出现在搜索结果中,其 URL 类似于包含 jsessionid 的 URL。
实际上它运行起来没有任何问题,但我更喜欢在没有 jsessionid 的情况下让 URL 清晰地出现在 Google 搜索结果中。
有什么帮助吗?
重点是:只要用户不登录或执行 POST 操作,就不要让您的应用程序创建会话。不要打电话request.getSession()
or request.getSession(true)
。不要为非登录用户创建或管理会话范围的 Bean。确保您使用的框架不会在未经您许可的情况下创建不必要的会话。
如果这是really由于您的应用程序的设计方式或由于所使用的 (MVC) 框架的限制/错误,这是不可能的,那么您最好的选择是将 Googlebot 请求重定向到没有 JSESSIONID 标识符的 URL。您可以使用Tuckey 的 URL 重写过滤器 http://www.tuckey.org/urlrewrite/为此(例如,Apache HTTPD 的众所周知的 Java 变体)mod_rewrite http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html)。这是其相关性的摘录配置示例页面 http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/3.2/guide.html.
隐藏来自 googlebot 的请求的 jsessionid。
<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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)