The Kat's Work - Blog
Main | Blog | Registration | Login
Sunday
2019-06-16
2:56 AM
Welcome Guest | RSS
Main » 2010 » December » 23

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.

Worst -

http://www.spree4.com/website.nsf? /bfb3d0325166a504802577de005cd97e/8ed70bc2c19e68f7802577de00601b62?OpenDocument
http://www.spree4.com/openPage.do?page=1
http://www.spree4.com/openPage.html?page=howItWorks
http://www.spree4.com/howItWorks.html
http://www.spree4.com/HowItWorks/

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.

<filter>
        <filter-name>UrlRewriteFilter</filter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
        <filter-name>UrlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
</filter-mapping>


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.

<rule match-type="wildcard">
       <from>/home/*/*/</from>
       <to>/home.htm?id=$1&page=$2&user=$3</to>
</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.
Views: 10466 | Added by: The_Kat | Date: 2010-12-23 | Comments (3)

Login form
Adverts
Search
Calendar
«  December 2010  »
SuMoTuWeThFrSa
   1234
567891011
12131415161718
19202122232425
262728293031
Entries archive
Site friends
  • Create your own site
  • Spree4.com
  • My Blog
  • Statistics

    Total online: 1
    Guests: 1
    Users: 0
    spree4
    Copyright MyCorp © 2019
    Website builderuCoz