|
Hello,
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: 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! Any idea how to accomplish this? The mapping is below. Thanks! Jason static mappings = { name publicMap: "/$action?/$id?" { def ret = UrlMappings.check(request) controller = ret.controller userName = ret.userName } } static check = { request -> def tokens = request?.serverName?.split(/\./) as List ?: [] def ret = [controller:'info'] if(tokens.size() > 3 && 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 } --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
I would deal with this at the DNS level, not the application level, since it's a domain issue and not a site issue.
- Rick
On Thu, Mar 1, 2012 at 4:02 PM, Jason Davis <[hidden email]> wrote: Hello, |
|
Not sure how I would work that out on a DNS level. Any ideas how to do that?
This is working for now, just doesn't seem optimal. name publicMap: "/$action?/$id?" { controller = { UrlMappings.check(request).controller } userName = { UrlMappings.check(request).userName } action = { UrlMappings.check(request).action ?: action } } Thanks, Jason On Thu, Mar 1, 2012 at 4:01 PM, Rick Jensen <[hidden email]> wrote: > I would deal with this at the DNS level, not the application level, since > it's a domain issue and not a site issue. > > - Rick > > On Thu, Mar 1, 2012 at 4:02 PM, Jason Davis <[hidden email]> wrote: >> >> Hello, >> >> 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: >> >> >> >> 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! >> >> >> Any idea how to accomplish this? The mapping is below. >> >> Thanks! >> Jason >> >> >> static mappings = { >> >> name publicMap: "/$action?/$id?" { >> def ret = UrlMappings.check(request) >> controller = ret.controller >> userName = ret.userName >> } >> } >> >> static check = >> { request -> >> def tokens = request?.serverName?.split(/\./) as List ?: [] >> def ret = [controller:'info'] >> if(tokens.size() > 3 && 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 >> } >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
short answer is you cant put code in the url mappings. I made this
work the way i wanted with a filter. maybe this will help someone else. Thank you stackoverflow. On Thu, Mar 1, 2012 at 4:11 PM, Jason Davis <[hidden email]> wrote: > Not sure how I would work that out on a DNS level. Any ideas how to do that? > This is working for now, just doesn't seem optimal. > > > name publicMap: "/$action?/$id?" { > controller = { UrlMappings.check(request).controller } > userName = { UrlMappings.check(request).userName } > action = { UrlMappings.check(request).action ?: action } > } > > Thanks, > Jason > > > > > > > > > > On Thu, Mar 1, 2012 at 4:01 PM, Rick Jensen <[hidden email]> wrote: >> I would deal with this at the DNS level, not the application level, since >> it's a domain issue and not a site issue. >> >> - Rick >> >> On Thu, Mar 1, 2012 at 4:02 PM, Jason Davis <[hidden email]> wrote: >>> >>> Hello, >>> >>> 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: >>> >>> >>> >>> 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! >>> >>> >>> Any idea how to accomplish this? The mapping is below. >>> >>> Thanks! >>> Jason >>> >>> >>> static mappings = { >>> >>> name publicMap: "/$action?/$id?" { >>> def ret = UrlMappings.check(request) >>> controller = ret.controller >>> userName = ret.userName >>> } >>> } >>> >>> static check = >>> { request -> >>> def tokens = request?.serverName?.split(/\./) as List ?: [] >>> def ret = [controller:'info'] >>> if(tokens.size() > 3 && 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 >>> } >>> >>> --------------------------------------------------------------------- >>> To unsubscribe from this list, please visit: >>> >>> http://xircles.codehaus.org/manage_email >>> >>> >> --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
