Search code examples
grailsgrails-2.0url-mapping

How to exclude specific keywords from UrlMapping in Grails?


I use the following url mapping in Grails:

"/$id"{
  controller = "user"
  action = "show"
}       

to map urls like mydomain.com/someusername

How do I attach constrains to the url mapping to exclude keywords like "login", "logout",...

I.e., mydomain.com/someusername should route to mydomain.com/user/show/someusername, mydomain.com/login should not route to mydomain.com/user/show/login.


Solution

  • You can use contrainsts for this mapping:

    "/$id"{
      controller = "user"
      action = "show"
      constraints {
        //add a validator for $id from url mapping
        id(validator: {
            return !(it in ['login', 'logout'])
        })
      }
    }