URL abstraction beloved by google, and hated by developers. If you have more than a passing knowledge of SEO you will "Know” that google (and others search engines.) loves abstracted urls. For good reason abstracted urls show google that even if you change the technology driving a website the urls will remain valid. In general the spectrum of urls go.
Best (or at least better)
However these abstracted urls (e.g. www.spree4.com/currentAuctions/
) are quite difficult to implement in dynamic websites where one "masterpage” may be used to create a large number of different webpages.
A colleague recently pulled this off in a asp.net application quite easily. So I became determined to find away to do this in Java, specifically Java Spring. This is were a rather wonderful product called Url Rewrite Filter
. This magnificent piece of script allows you to create a filter in your java application that will forward an abstracted url to a url your app will understand.
There are several setups, here I will describe how to create seamless abstraction. For example your users requests www.spree4.com/auctionDetails/Amazon+Kindle+3G/
and your application responds with the content for www.spree4.com/auctionDetails.html?item=33
without the user(and the googlebots.) being aware of any shenanigans.
First off go and download urlrewritefilter-3.2.0.zip from www.tuckey.org/urlrewrite/
. Once downloaded extract into your web-inf this will place an xml file called urlrewrite into your webinf and add the required jars into your lib.
Next add the following to web xml.
this will create a filter that will forward all url requests to be processed by the urlrewriter. As you can see this default filter has all requests (/*) being subject to the urlRewriterFilter. I would suggest leaving this as it is the urlrewriter.xml allows for a lot of control.
Next we need to set some rules. In the urlrewriter.xml file we already have some examples very kindly supplied by the developer. The first to do with a rule is to set the from. In version 3.2 we can use regular expression (arrrrrrggggghhhh!!) or much nicer wildcards (i.e /test/*/). I’d choose wildcards but have a good look at the symantics of the wildcards in the manual.
Once you have a rule with a from you need to let the url rewrite filter code now what form the url should take. To do this we set the to of the rule. In the "to” we refer to the wildcarded/regex from the from as $<occurance> (i.e. in /test/*/*/ the text of the first wildcard is referenced as $1). Below is a working rule.
The rule above would take the url www.spree4.com/home/3/2/TheKat/
which your app would not understand and silently convert it to www.spree4.com/home.htm?id=3&page=2&user=TheKat
There you go using this you can easily abstract your urls……but wait there’s more reading into the manual urlrewriter allows for lots of advanced options I can see another blog coming.
Remember there is a manual located at here.