0

我有一个正在从事当前工作的 grails 应用程序。我必须在网站的移动版本上工作,并且我想在 UrlMappings.groovy 中了解请求是来自 www.mysite.com 还是来自 m.mysite.com。知道我该怎么做吗?

更新:

我当前的映射看起来像这样 --->

导入静态 org.apache.commons.lang.StringUtils.*

class UrlMappings {
    static mappings = {
        "/$controller/$action?/$id?"{
            constraints {
                // apply constraints here
            }
        }

        "/$lang/$controller/$action?/$id?"{
            language = "${lang}"
            constraints {
                // apply constraints here
            }
        }

        // Start :: Shopping Tools internal URLs
        "/modelLine/build/$year/$modelLineCode/"(controller:'modelLine', action:'build')
        "/colors/index"(controller:'colors', action: 'index')
        "/packages/index"(controller:'packages', action: 'index')
        "/accessories/index"(controller:'accessories', action: 'index')
        "/summary/index"(controller:'summary', action: 'index')

        // Start :: Spanish :: Shopping Tools internal URLs

        "/$lang/modelLine/build/$year/$modelLineCode/"(controller:'modelLine', action:'build')
        "/$lang/colors/index"(controller:'colors', action: 'index')
        "/$lang/packages/index"(controller:'packages', action: 'index')
        "/$lang/accessories/index"(controller:'accessories', action: 'index')
        "/$lang/summary/index"(controller:'summary', action: 'index')

        // End :: Spanish :: Shopping Tools internal URLs
        // End :: Shopping Tools internal URLs


        // Default Home Page
        "/$lang?"(controller:"modelLine", action:"index"){
            constraints {
                lang inList:['en','fr'] // avoids invalid matching
            }
        }

        "/admin"(controller:"admin", action:"index")
        // Error page definitions
        "404"(controller:"errors", action:"notFound")
        "500"(controller:"errors", action:"serverError")
        "403"(view:'/login/denied')
        "402"(view:'/login/denied')
        "401"(view:'/login/denied')
    }
}

如何更改它们以检测 m.mysite.com 请求?

4

4 回答 4

1

您可以在 Grails 3 中创建过滤器或拦截器,并检查 request.getHeader("User-Agent") 如果它是移动的,然后将 url 重定向到您想要的任何地方。

于 2016-02-26T16:14:20.850 回答
1

它在请求对象中,在所有控制器操作中都可用request.

在此处检查可用的属性https://grails.github.io/grails-doc/3.0.x/ref/Servlet%20API/request.html

于 2016-02-26T04:10:14.820 回答
1

如果您有不同的移动站点控制器,为什么不更改m.mysite.com指定移动映射中的所有链接?移动设备中的exampleController和操作somethingMobile

m.mysite.com/mobile/example/somethingMobile

桌面相同,但有操作something

mysite.com/example/something
于 2016-02-25T23:10:17.643 回答
0

我通过更改 apache 级别的 url 解决了这个问题。将其更改为 www.mysite.com/m

于 2016-02-26T20:09:06.313 回答