我正在处理当前工作的grails应用程序。我必须处理该网站的移动版本,我想在UrlMappings.groovy中查看该请求是来自www.mysite.com还是m.mysite.com。知道我该怎么办?
更新
我目前的映射看起来像这样--->
import static 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请求?
答案 0 :(得分:1)
如果您的移动网站有不同的控制器,为什么不更改 var options4 = {
chart: {
title: 'Temperatura',
subtitle: 'Últimas 4 horas'
},
vAxes: {
0: {title: 'Temperatura'},
1: {title: 'Resto'}
},
series: {
0: {targetAxisIndex: 0},
1: {targetAxisIndex: 0},
2: {targetAxisIndex: 1},
3: {targetAxisIndex: 1},
4: {targetAxisIndex: 1}
},
width: 900,
height: 500
};
中指定移动网站的所有链接?移动设备中的m.mysite.com
和操作exampleController
:
somethingMobile
同样适用于桌面但行动m.mysite.com/mobile/example/somethingMobile
:
something
答案 1 :(得分:1)
它位于请求对象中,在所有控制器操作中均可用作request
。
检查https://grails.github.io/grails-doc/3.0.x/ref/Servlet%20API/request.html
中的可用属性答案 2 :(得分:1)
您可以在Grails 3中创建过滤器或拦截器,如果是移动设备,则检查request.getHeader(“User-Agent”),然后将URL重定向到您想要的位置。
答案 3 :(得分:0)
我通过更改apache级别的url解决了这个问题。将其更改为www.mysite.com/m