title: Logic block in Grails URLMappings
body: <p>My site has urls like 'http://someRandomUsername.mysite.com'.
  Sometimes users will try urls like
  'http://www.someRandomeUsername.mysite.com'. I'd like to have some
  logic in my url mappings to deal with this.
  With the mappings below when I hit the page , with or without the
  unneeded www, I get:</p>
  
  <p>2012-03-01 14:52:16,014 [http-8080-5] ERROR [localhost].[/ambit]  -
  Unhandled exception occurred whilst decorating page
  java.lang.IllegalArgumentException: URL mapping must either provide a
  controller or view name to map to!</p>
  
  <p>Any idea how to accomplish this? The mapping is below.</p>
  
  <p>Thanks!
  Jason</p>
  
  <p>static mappings = {</p>
  
  <pre><code>         name publicMap: "/$action?/$id?" {
                   def ret = UrlMappings.check(request)
                   controller = ret.controller
                   userName = ret.userName
           }
  }
  
  static check =
  { request -&gt;
           def tokens = request?.serverName?.split(/\./) as List ?: []
           def ret = [controller:'info']
           if(tokens.size() &gt; 3 &amp;&amp; token[0] == 'www')
           {
                   ret.userName = tokens[1]
                   ret.controller = 'redirect'
                   ret.action = 'removeWWW'
           }
           else if(tokens.size() == 3)
           {
                   ret.userName = tokens[0]
                   ret.controller = 'info'
           }
  
           return ret
  }
  </code></pre>