开发者

Is it possible to map a root domain URL to a Grails' controller?

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.


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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜