#67 open

Automatic redirection for changed item and basket URLs

Reported by James | September 23rd, 2008 @ 10:07 AM | in 1.4


When basket names are changed or items are moved between baskets, URLs previously pointing to items within the basket or the moved items no longer work.

This is a problem for sites which have been deep-linked by other sites or heavily indexed in search indexes. It also creates accessibility challenges.


A system should be implemented to automatically perform a 301 redirect to the new URL for an item for basket when an old one is visited.

Comments and changes to this ticket

  • Walter McGinnis

    Walter McGinnis November 23rd, 2008 @ 04:03 PM

    The easiest solution is probably to write page under public/ at the former URL to redirect the new page.

    The only problem with this with capistrano deployments. The public directory would get cleared after deployment. So a model of 302 that should persist through deployments could be added to the data model and a simple backgroundrb worker could write them out at system restart.

  • Walter McGinnis

    Walter McGinnis January 2nd, 2009 @ 01:42 PM

    Here's a good post that gives some background on redirects:


    I think we should also keep in my the case where an entire basket's data is exported to a totally new Kete site.

    I suggest we wrap this up as a plugin and name it "bait_and_switch".

  • Walter McGinnis

    Walter McGinnis March 1st, 2011 @ 10:41 AM

    • Milestone order changed from “0” to “0”

    I've implemented a hardcoded redirect_to that may provide some insight into how to best implement this.

    In app/controllers/application_controller.rb I replaced the following

    def rescue_404
    @displaying_error = true @title = "404 Not Found" render :template => "errors/error404", :layout => "application", :status => "404"



    def rescue_404
    unless request.url.include?('/old_basket_urlified_name/')

     @displaying_error = true
     @title = t('application_controller.rescue_404.title')
     render :template => "errors/error404", :layout => "application", :status => "404"


     new_url = request.url.sub('/old_basket_urlified_name/', '/new_basket_urlified_name/')
     redirect_to new_url, :status => :moved_permanently



    Of course this is hardcoded with basket urlified_name for old and new basket. However, it shows where we should make the look up of the old pattern (registered in our PermanentlyMoved class perhaps with "from" being old pattern and "to" being new pattern) and replace it with the new.

    Fairly simple rather than writing out files and clearing them/recreating them on redeploy.

    This could work with items being moved to new baskets, too, by registering the "from" pattern as the rest of the url starting from the basket urlified_name and the "to" pattern being the same, but with the new basket urlified_name.

  • Walter McGinnis

    Walter McGinnis June 21st, 2012 @ 07:36 PM

    • State changed from “new” to “open”
    • Assigned user changed from “Kete” to “Walter McGinnis”
    • Milestone set to 1.4
    • Milestone order changed from “20” to “0”

    This feature should accommodate these use cases (all accept status, but will default to 301):

    • complete source url redirects to complete target url with status (e.g. old site urls mapped to new Kete version of content OR Kete item moved to a new basket)

    • partial source url (a pattern) redirects to complete target url (likely a set of old site urls under a unified stub mapped to single Kete location)

    • partial source url (a pattern) redirects to a partial target url (a pattern) (e.g. basket rename)

    We'll have a UrlRedirect model to store source_url_pattern, target_url_pattern, and status. We'll use the 404 modification to return the redirect response.

    We'll also hook into edits of baskets and items (callback on model) to create corresponding instances of UrlRedirect model.

    We'll also create a rake task for creating instances of UrlRedirect model based on import from XML version of Excel spreadsheet.

  • Walter McGinnis

    Walter McGinnis June 21st, 2012 @ 07:39 PM

    The model name we will use will be RedirectRegistration to avoid confusion with with redirect method.

  • Walter McGinnis

    Walter McGinnis June 22nd, 2012 @ 12:54 AM

    Implemented and merged to master.

    A couple assumptions in the implementation:

    • locales should be left out of source_url_pattern and target_url_pattern (even when a full url pattern, i.e. including host)

    • incomplete patterns are going to be /some/dir/structure/ in form and include the absolute path after the host (except /locale_code/ at beginning)

    Private versions of items are a bit untested. I'm not sure if they will work quite yet. Will open a new issue if not.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Kete was developed by Horowhenua Library Trust and Katipo Communications Ltd. to build a digital library of Horowhenua material.

People watching this ticket