我有一个Grails应用程序,正在处理当前的工作。我必须处理网站的移动版本,无论请求来自www.mysite.com还是m.mysite.com,我都想捕获UrlMappings.groovy。知道我该怎么做吗?
更新:
我当前的映射看起来像这样--->
导入静态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请求?
最佳答案
如果您为移动网站使用了不同的 Controller ,为什么不更改m.mysite.com
中用于指定移动设备映射的所有链接?对于移动设备中的exampleController
和 Action somethingMobile
:
m.mysite.com/mobile/example/somethingMobile
与台式机相同,但具有
something
Action :mysite.com/example/something
关于grails - 如何在Grails应用程序中基于m.mysite.com重定向到移动页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35637486/