如何在 STRUTS 上重写 SEO 友好的 URL?
我们有一个使用 Struts 框架使用 Java 进行编码的网站。该网站的 URL 不利于搜索引擎优化。全部都是像下面这样的
../buyerApplication.do&companyId=2323
现在我们想让这些 URL SEO 友好,我搜索并找到了这些解决方案:
- tuckey.org/urlrewrite :但我不依赖这个系统。
- 添加 标题“&”后链接结束例如 “../newsId=33233&城市中的艺术是否等于城市中的艺术” :在这个解决方案中我不确定 效果很好。
我正在等待您的建议来最好地解决这个问题。
We have a website which is coded Java with Struts Framework. The WebSite's Urls are not seo friendly. All of them are like below
../buyerApplication.do&companyId=2323
Now We want to make these URLs SEO friendly and I searched and found these solutions:
- tuckey.org/urlrewrite : but i don't rely on this system.
- adding
title end of link after '&' such as
"../newsId=33233&does-art-in-the-city-equal-art-for-the-city"
: In this solution I am not sure it
works well.
I am waiting your sugestions to solve this problem best.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我实际上使用了 URLRewriter (http://tuckey.org/urlrewrite/),您在原始文件中引用了它问题。设置非常简单,完美满足了我的需求。
I actually used URLRewriter (http://tuckey.org/urlrewrite/), which you referenced in your original question. It was very easy to set up and filled my needs perfectly.
就这一点而言,您需要一个过滤器。
如果您想保留现有应用程序的架构,则需要定义和创建一组规则,将不友好的 URL 转换为友好的 URL,并让过滤器进行转换并将请求转发到不友好的 URL 。
如果无法修改现有应用程序,但您想基于此想法创建一个新应用程序,则可以考虑使用单个页面控制器来转换 HttpServletRequest#getPathInfo()/getRequestURI() 来执行适当的操作类(命令模式),最后将请求转发到适当的 JSP 页面。不确定它如何适合 Struts,因为我以前没有使用过 Struts。
To the point, you need a Filter for this.
If you want to keep your existing application's architecture, you'll need to define and create a set of rules to convert unfriendly urls to friendly urls and let the filter convert it and forward the request to the unfriendly url.
If there is no means of modifying an existing application but you want to create a new application based on this idea, you could consider to having a single page controller which translates the HttpServletRequest#getPathInfo()/getRequestURI() to execute the appropriate action class (command pattern) and finally forward the request to the appropriate JSP page. Not sure how that would fit into Struts as I haven't worked with Struts previously.
对于它的价值,您还可以查看 REST 插件 http:// /struts.apache.org/2.x/docs/rest-plugin.html,这将使您的 URL 更加友好
For what it's worth, you can also look at the REST plugin http://struts.apache.org/2.x/docs/rest-plugin.html, which amongst other things will make your URLs more friendly