Java and SEO URLS

☆樱花仙子☆ 提交于 2019-12-04 07:26:46

This might be of interest to you:

http://tuckey.org/urlrewrite/

If you are familiar with mod_rewrite on Apache servers, this is a similar concept.

If you're using the new Spring-MVC annotations, you can use the @RequestMapping and @PathVariable annotations:

@RequestMapping("/articles/{subject}")
public ModelAndView findArticleBySubject(@PathVariable("subject") String subject)
{
   // strip out the '-' character from the subject
   // then the usual logic returning a ModelAndView or similar
}

I think it is still necessary to strip out the - character.

http://mysite.com/articles/my-article-subject is a much stronger URL than http://mysite.com/articles/articleId - especially if the title and header tags match "my-article-subject" too and you have "my", "article" and "subject" in the content of the page.

For example if you want the url

http:///blog/11/12/2009/my-hello-world-post/

then configure the servlet mapping

<servlet>
<servlet-class>com.blog.Blog</servlet-class>
<servlet-name>blog</servlet-name>
<servlet-class>com.blog.Blog</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>blog</servlet-name>
<url-pattern>/blog/*</url-pattern>
</servlet-mapping>

and in the servlet code

String url = request.getPathInfo();
StringTokenizer tokens = new StringTokenizer(url,"/");
while(tokens.hasMoreTokens()){
out.println("
"+tokens.nextToken());
}

Use these params to get the data from database and display to user

The standard Java web frameworks are not ready for those kind of URL.

AFAIK, SpringMVC does not support this kind of URL.

There are two frameworks I'm sure that support this kind of URL: Mentawai and VRaptor.

If you're only looking for a SEO optimization you could design your URLs this way:

http://mysite.com/articles/my-article-subject/articleId

or

http://mysite.com/articles/articleId/my-article-subject

and just ignore the part my-article-subject when evaluating the urls.

Amazon does something like that with their URLs:

http://www.amazon.com/Dark-Crystal-Jean-Pierre-Amiel/dp/B00000JPH6/ref=sr_1_1?ie=UTF8&s=dvd&qid=1240561659&sr=8-1

Here the Text "Dark-Crystal-Jean-Pierre-Amiel" is totally irrelevant because the article is identified by the id B00000JPH6.

Edit: In fact I just noticed that right here on SO this exact technique is used to generate SEO-friendly URLs...

I have used pretty faces http://ocpsoft.org/prettyfaces/ for our application because it was JSF based. This is a very neat solution. Not sure if it will work for Spring MVC Have a look at our URL

http://www.skill-guru.com/cat/certification-mock-test

http://www.skill-guru.com/test/81/core-spring-3.0-certification-mock

http://www.skill-guru.com/tutor/Pro+ESL

Earlier we had non SEO friendly URL's with jsession Id's appended to it. Now it is all neat and clean with the help of pretty filter. This is in very in line with wordpress url.

generate url containing both id and description like this url http://stackoverflow.com/questions/784891/java-and-seo-urls . in the servlet parse the url and then use id for fetching data from database. Same Technique is applies on this stackoverflow page too. look at the url. its http://stackoverflow.com/questions/784891/java-and-seo-urls however only questionId is considered and description is ignored. try http://stackoverflow.com/questions/784891 or http://stackoverflow.com/questions/784891/abcdxyz . you will get same page. this is very good technique to generate seo urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!