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.
you could do the following in javascript:
This would need to go in your header.php
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
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.
Solution:
Download and install plugin : CSS & Javascript Toolbox
Add this javascript to the page you want to redirect from.