hamo
hamo

Reputation: 2347

Java and SEO URLS

I'm building a webapp using spring MVC and am curious as to whether there is any clean way to make SEO urls.

For example, instead of http://mysite.com/articles/articleId and the such, have:

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

Upvotes: 5

Views: 8664

Answers (8)

vsingh
vsingh

Reputation: 6779

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.

Upvotes: 0

Larkut
Larkut

Reputation: 1

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

Upvotes: -1

Dick Chesterwood
Dick Chesterwood

Reputation: 2659

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.

Upvotes: 6

B.E.
B.E.

Reputation: 5080

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...

Upvotes: 0

razenha
razenha

Reputation: 7752

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.

Upvotes: 1

Thejesh GN
Thejesh GN

Reputation: 1128

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

Upvotes: 1

Fenton
Fenton

Reputation: 251282

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.

Upvotes: 1

user7094
user7094

Reputation:

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.

Upvotes: 5

Related Questions