Friday, November 19, 2010

Konakart and Clean Search Engine Friendly URLs

I've finally got round to cleaning up the product and category URLs in Konakart 5.0.0.0 Community Edition.

Introduction

Out of the box Konakart appends SEO data including product name, category name, manufacturer and model number to the url by performing a 302 redirect. You can see this in action by visiting the Konakart demo site. Hovering over the first product under "Latest Products" you will see a similar URL to the one below in the status bar:

http://www.konakart.com/konakart/SelectProd.do?prodId=28

After following the link you will see the URL on the address bar change something similar to:

http://www.konakart.com/konakart/SelectProd.do?prodId=28&manufacturer=Microsoft&category=Keyboards&name=Bundle+Saver&model=MSMOUSEKBBUNDLE

This has been achieved in the struts action class by testing for the existence of the appended URL data. If it exists the product is loaded and forwarded to the view. If not then the data is appended to the URL and a 302 redirect to the formulated URL is performed.

While this appears to get SEO data into the URL I've googled a few products and noted that the URL within the search results doesn't contain the SEO data. The same can be said for bing and yahoo.

I've used a mixture of Url Rewrite Filter, Custom tags, and a couple of modified struts action classes to clean up these URL's to look more like the URL below without the need for 302 redirects:

http://www.konakart.com/konakart/Hardware/Keyboards/Microsoft/Bundle-Saver-28.html

Making the changes

To implement the clean URL's first download the latest release of Konakart Community Edition. Then download the KonakartSEO.zip file containing the new Action classes, URLRewrite jar, and Custom tags.

Run the Konakart Installer and once installed unzip the KonakartSEO.zip file straight into the konakart installation directory.

You are now ready to start the Konakart server

What's Changed?

WEB-INF/urlrewrite.xml
This is the configuration file for the url rewrite filter. It uses regular expressions to match url's and rewrite them.

WEB-INF/web.xml
I've added the url rewrite filter and init params to the standard konakart web.xml file

WEB-INF/struts-config.xml
The two actions: SelectProd.do and SelectCat.do have been updated to use the modified action classes that are in KonakartSEO.jar. The modified action classes have had the redirect removed when no SEO data was appended to the URL.

WEB-INF/lib/KonakartSEO.jar
Jar file containing custom JSP Tags, tld and the modified action classes.

WEB-INF/lib/urlrewrite-3.2.0.jar
Latest version of the URL rewrite filter

WEB-INF/jsp/
All the JSP files have been updated to make use of the custom JSP tags in place of <html:link > tags. Also, MainLayout.jsp has been ammended by adding a custom tag that creates an HTML base tag so relative urls to images, scripts etc are resolved correctly following url rewriting.

3 comments:

  1. Hi Craig,

    This is awesome. Exactly what I was looking for....with that being said I click on a product category or an item and I don't see the re-write result. What do I have to edit in order to get the friendly url? urlrewrite.xml?

    Thanks!

    Brian

    ReplyDelete
  2. Hi Brian,

    Sorry for the long delay in replying, I hadn't set up email notification of posted comments. That's fixed now.

    This should work straight out of the box. Can you confirm that you can see the URLWrite status page at http://localhost:8780/konakart/status (I assume you are using Konakarts standard installation)? Also is there any output in the tomcat log files?

    Craig

    ReplyDelete