在Wordpress中将页面重定向到移动版本 [英] Redirect Page to Mobile Version in Wordpress

查看:82
本文介绍了在Wordpress中将页面重定向到移动版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Wordpress网站中使用htaccess设置移动重定向.

I would like to setup mobile redirection using the htaccess in my Wordpress website.

我有一个移动网站(mobile.domain.com)和常规网站(domain.com),每个网站的永久链接都相同,例如domain.com/page-one/mobile.domain.com/page-one/,因此重定向到移动网站中的同一页面似乎很容易.

I have a mobile site (mobile.domain.com) and regular site (domain.com) The permalinks will be the same for each site e.g. domain.com/page-one/ and mobile.domain.com/page-one/ so it seems like it should be fairly easy to redirect to the same page in the mobile site.

我尝试过在线查找,但找不到我需要的东西,有人可以帮忙吗?如果一个插件已经存在,我会很乐意.

I've tried looking online and cant find what I need, can anyone help with this? I would be happy just using a plugin if one already exists.

推荐答案

我知道这是一篇过时的文章,但是在弄清楚这一点后,我认为我使用的解决方案在这里值得一提.

I know this is an old post, but after figuring this out I think the solution I used is worth mentioning here.

每个人都知道简单的Javascript重定向会很好用,但是如果您希望用户最终进入具有完全相同的路径名的页面怎么办?如果您有此重定向,则"example.com/contact"将重定向到"mobile.example.com"-请注意,这不是联系人页面的移动版本.

Everyone knows that a simple Javascript redirect will work great, but what if you want the user to end up on a page that has the exact same path name? If you have this redirect, then "example.com/contact" will be redirected to "mobile.example.com" - notice how this is not the mobile version of the contact page.

解决方案是在主标题中包含一个Javascript代码段,该代码段将告诉每个页面在重定向时保持相同的路径名,例如"/contact".一个警告是,每个移动页面的名称必须与桌面版本相同-/whatever和/whatever.

The solution is to have a Javascript snippet in the main header that will tell each page to keep its same pathname when redirected, such as "/contact". The one caveat is that each mobile page must be named the same as the desktop version - /whatever and /whatever.

<script type="text/javascript">
    <!--
    if (screen.width <= 800) {
        document.location = "https://mobile.example.com" + window.location.pathname;
    }
</script>

这篇关于在Wordpress中将页面重定向到移动版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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