views:

57

answers:

3

Let's have an example: A grails project, myproj, is deployed in Tomcat 6. It can be accessed anywhere thru this link: http://www.mycompany.com/myproj.

Let's say we purchase another domain, http://newcompany.com, and we would like to point it to http://www.mycompany.com/myproj/url.

If I go to http://newcompany.com/12345, it should be the same as doing http://www.mycompany.com/myproj/url/12345.

Can anyone tell me if this is possible? How to implement it (change Tomcat 6 config, add code in UrlMappings.groovy)?

Thanks in advance.

+2  A: 

Having 2 domains pointing to the same site is straightforward if you front Tomcat with Apache and use url rewriting via mod_rewrite and/or mod_jk.

It's also possible to add aliases to your tomcat config, though I don't think you can have one alias with a context path and one on the root using just Tomcat so you may need to make your app aware of the different hosts.

The bigger question is do you really want 2 domains for the same instance as it could confuse users and search engines and will almost certainly cause bugs.

Dave
thanks for the tips. actually, the purpose of the 2nd domain is to act as an internal and custom url shortening service/stats tracker that will be used ONLY by the 1st domain (project). instead of creating 2 diff grails project, we're thinking if they can be integrated as a single project. what do you think? does this make sense?
firnnauriel
I'd probably use Apache to do achieve that
Dave
A: 

There is a Java web filter called URLRewrite that will probably do what you want - it does the same job for Tomcat as mod_rewrite does for Apache.

mojones
A: 

You can use the UrlMappings.groovy to map a controller to your root index. For example, I wanted my root index "/" to be controlled by my loginController.groovy. So I added the UrlMapping entry "/"(controller:'login', action:'index')

The UrlMappings.groovy is shown below:

class UrlMappings {
    static mappings = {
        // MJC - added this in an attempt to give a controller some control
        // over the root.
        "/"(controller:'login',action:'index')

      "/$controller/$action?/$id?"{
            constraints {
                // apply constraints here
            }
        }
        // "/"(view:"/index")
        "500"(view:'/error')
    }

}

Hope this helps...

  • Monte C. Concept Automation Support, Inc.
Monte Condos