如何在grails应用程序中基于m.mysite.com重定向到移动页面 [英] How to redirect to mobile page based on m.mysite.com in grails app

查看:144
本文介绍了如何在grails应用程序中基于m.mysite.com重定向到移动页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一份我目前工作中使用的Grails应用程序。我必须在网站的移动版本上工作,并且我想在UrlMappings.groovy中查看请求是否来自www.mysite.com或m.mysite.com。任何想法我怎么能做到这一点?



更新:



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



import static org.apache.commons.lang.StringUtils。*

 class UrlMappings {
static mappings = {
/ $ controller / $ action?/ $ id?{
constraints {
//在这里应用约束


$ b $ / $ lang / $ controller / $ action?/ $ id?{
language =$ {lang}
约束{
//在这里应用约束
}
}

//开始::购物工具内部URL
/ modelLine /建立/ $ year / $ modelLineCode /(控制器:'modelLine',动作:'build')
/ colors / index(控制器:'颜色',动作:'索引')
/ packages / index(controller:'packages',action:'index')
/ accessories / index(controller:'a coutories',action:'index')
/ summary / index(控制器:'summary',action:'index')

// Start :: Spanish ::购物工具内部URL
$ b $ / lang / modelLine / build / $ year / $ modelLineCode /(controller:'modelLine',action:'build')
/ $ lang / colors / index')(控制器:'颜色',动作:'索引')
/ $ lang / packages / index(控制器:'包',动作:'索引')
/ $ lang / (控制器:'摘要',动作:'索引')
$ b $ / $ lang / summary / index b //结束::西班牙语::购物工具内部网址
//结束::购物工具内部网址


//默认主页
/ $ lang?(controller:modelLine,action:index){
constraints {
lang inList:['en','fr'] //避免无效匹配
}

$ b $/ admin(controller:admin,action:index)
//错误页面定义
404(controller:errors ,action:notFound)
500(controller:errors,action:serverError)
403(view:'/ login / denied')
(查看:'/ login / denied')
401

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

解决方案

您可以在Grails 3中创建过滤器或拦截器,并检查request.getHeader(User-Agent)移动然后重定向的网址,你想要的。

I have a grails app I am working on at my current job. I have to work on the mobile version of the website and I want to catch in UrlMappings.groovy whether the request is coming from www.mysite.com or m.mysite.com. Any idea how can i do that?

UPDATE:

My current mappings look like this --->

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')
    }
}

How do I change them to detect an m.mysite.com request?

解决方案

You can create a filter or Interceptor in Grails 3 and check request.getHeader("User-Agent") if it is mobile then redirect the url where ever you want.

这篇关于如何在grails应用程序中基于m.mysite.com重定向到移动页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆