Redirect Page to Mobile Version in Wordpress

2020-05-06 18:13发布

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

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.

4条回答
对你真心纯属浪费
2楼-- · 2020-05-06 18:28

you could do the following in javascript:

<script language="JavaScript" type="text/javascript">
if ((screen.width>=1024) && (screen.height>=768))
{
 window.location.replace('example.html');
}

</script>

This would need to go in your header.php

查看更多
我命由我不由天
3楼-- · 2020-05-06 18:34

Check this website http://detectmobilebrowsers.com/ for php or javascript code. You can use PHP or Javascript, that you have to paste within header.php

查看更多
别忘想泡老子
4楼-- · 2020-05-06 18:35

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

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.

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>
查看更多
Ridiculous、
5楼-- · 2020-05-06 18:38

Solution:

Download and install plugin : CSS & Javascript Toolbox

  • (make sure to always backup before downloading and installing plugins)

Add this javascript to the page you want to redirect from.

<script type="text/javascript">  
<!--  

if (screen.width <= 600)  

{   
   window.location="http://www.yourmobilesite.com";  
}  
//-->  
</script>
查看更多
登录 后发表回答