Dynamic link rewriting


New member
Hi there.

I've had no luck searching for a complete solution to this, so forgive me if I've missed it.

My application needs to operate in the context of multiple business centres in different countries, and we want our users to be able to operate in browser and across tabs, such that each tab's URL may contain a different country code, for example http://myapp/uk/controller/action/list or http://myapp/fr/controller/action/list.

A legacy system that uses sessions to store locale info has proved to create problems when users are switching country in one tab, and performing operations in a different tab assuming it to still be associated with a different business centre. So we don't want to use sessions - we need to tie the user's per-browser-tab actions to a locale, and not the user's session. So far, here is what I have:


class UrlMappings {

  static mappings = {
    "/$country/$controller/$action?/$id?" {
      constraints {
        country(matches: "(uk|fr...etc)")

and a filter that looks up the legacy id for the specified country code:


class NetworkFilters{

  def filters = {
    networks(controller:'*', action:'*') {
      before = {

        def network = Network.findByCountry(params.country)
        params.idNetwork = network.id


So I'm haapy enough that I have got a valid URL from the user. What I want to do next is the part I'm struggling with. I want to dynamically rewrite every URL generated by grails so that all the CRUD stuff, every redirect, g:link etc is rewritten to include the country code. Am I mad? If anyone has a suggestion I'd welcome it.

Also, being a newbie, verbosity is preferred over brevity! Thanks in advance:)