【问题标题】:How do I create a redirect from mobile to desktop site?如何创建从移动网站到桌面网站的重定向?
【发布时间】:2013-09-09 23:33:15
【问题描述】:

当用户登陆m.example-site.com/hello时,我想将他们重定向到hello.com/example

在使用 Moovweb 时,我怎样才能最好地做到这一点? (理想情况下,它会提供最快的用户体验。)

【问题讨论】:

    标签: redirect http-status-code-302 moovweb tritium


    【解决方案1】:

    如果您使用的是stdlib 混合器,您可以通过使用氚中的redirect_temporaryredirect_permanent 函数来完成此操作。

    redirect_temporary(Text %url) 函数将导致向客户端返回一个302 HTTP 重定向响应。

    redirect_permanent(Text %url) 函数将导致向客户端返回一个301 HTTP 重定向响应。

    要完成您的具体示例,您可以匹配 $path 变量,然后调用您喜欢的任何重定向函数。以下是永久重定向的示例:

    match($path, "/hello") {
      redirect_permanent("http://hello.com/example")
    }
    

    【讨论】:

      【解决方案2】:

      您也可以使用 Javascript 来完成此操作。

      当用户登陆m.example-site.com/hello时,在文档的头部添加一个<script>标签,指定一个新的window.location

      所以,它看起来像:

      <script>
      // similar behavior as an HTTP redirect
      window.location.replace("hello.com/example");
      </script>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多