(function () { var url = location.href; // replace www.test.com with your domain if ( (url.indexOf('www.test.com') != -1) && navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i) ) { var newUrl = url.replace('http://www', 'http://m'); location.href = newUrl; } })();