Java and SEO URLS

2019-04-09 03:13发布

问题:

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

回答1:

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.



回答2:

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.



回答3:

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.



回答4:

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



回答5:

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.



回答6:

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



回答7:

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.



回答8:

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