How to Redirect Website to a Mobile Version when Accessed on a Mobile Device

Tontuf Co.
Bitcoin price
$ 103983-3.6%
Ethereum price
$ 2478.26-6.1%
Tether price
$ 1.00304+0.3%
XRP price
$ 2.15722-6.9%
BNB price
$ 644.671-1.8%
Solana price
$ 146.785-6.9%
USDC price
$ 1.00361+0.5%
Letscoin price
$ 1.00294+0.4%
TRON price
$ 0.27438-2.3%
Cardano price
$ 0.60699-7.3%
NULS
$ 0.09333+224%
KEEP
$ 0.10247+27.0%
MLN
$ 9.58368+12.0%
BMX
$ 0.29536+4.4%
SOLIDX
$ 9.60052+4.3%
0X0
$ 0.11194-23.0%
AERO
$ 0.70309-19.2%
BOBO
$ 0.00000-17.6%
ZEUS
$ 0.19034-17.3%
MICHI
$ 0.03088-17.1%

Hello guys in this blog I will tell you how to redirect a website to a mobile version when accessed on a mobile device

Create a mobile website that provides a great user experience
Redirect your site for mobile users


Separate URLs | Search for Developers | Google Developers


Using a JavaScript code you can redirect your mobile visitors to your mobile site. This JS code can either detect screen size or the user-agent.


Open the HTML file or your website's code page

Search -  <head> in your template 

Copy and paste this code below the <head> tag 


 <script type="text/javascript">  
<!--
if (screen.width <= 699) {
document.location = "mobile.html";
}
//-->
</script>

“mobile.html” would be replaced with the location of wherever your mobile version resides. 

This technique could be adapted to load an alternate stylesheet as well.

Save the theme or code 

For iPhones/iPods Specifically

 <script language=javascript>  
<!--
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
location.replace("http://url-to-send-them/iphone.html");
}
-->
</script>


And boom you are done 



PHP Method

For this script to work your page extensions must be .php and your hosting account must support PHP. Add the following code to your website’s section.

 <?php  
$iphone = strpos($_SERVER[‘HTTP_USER_AGENT’],”iPhone”);
$android = strpos($_SERVER[‘HTTP_USER_AGENT’],”Android”);
$palmpre = strpos($_SERVER[‘HTTP_USER_AGENT’],”webOS”);
$berry = strpos($_SERVER[‘HTTP_USER_AGENT’],”BlackBerry”);
$ipod = strpos($_SERVER[‘HTTP_USER_AGENT’],”iPod”);

if ($iphone || $android || $palmpre || $ipod || $berry == true)
{
echo “<script>window.location=’http://m.site.com'</script>”;
}
?>

Replace http://m.site.com with your mobile site’s URL.

Tags
Our website uses cookies to enhance your experience. Learn More
Accept !