简体   繁体   中英

Adapt PHP Web Sites for Mobile Devices: Redirect to mobile subdomain "m"

I want to redirect html desktop pages to html mobile pages from the "m" subdomain. I believe I must change something in pages, so I find some settings on other web platforms. The problem is that, does not working.

In desktop pages add this code (change the link):

<link rel="alternate" media="only screen and (max-width: 640px)" href="https://m.yoursite.com/test.html" />

<link rel="amphtml" href="https://m.yoursite.com/test.html?amp" />

In mobile pages add this (change the link):

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"/>

<meta name="apple-mobile-web-app-capable" content="yes"/>

<link rel="canonical" href="https://m.yoursite.com/test.html"/>

<link rel="amphtml" href="https://m.yoursite.com/test.html?amp"/>

<link rel="alternate" media="only screen and (max-width: 640px)" href="https://m.yoursite.com/test.html"/>

<meta name="cXenseParse:pageclass" content="article"/>

<meta name="cXenseParse:url" content="https://m.yoursite.com/test.html"/>

<meta name="robots" content="follow,index,noodp"/>

<meta name="robots" content="max-snippet:-1, max-image-preview:large, max-video-preview:-1"/>

<meta name="referrer" content="origin-when-cross-origin"/>

<meta property="og:url" content="https://m.yoursite.com/test.html" />

Do I need to change something in php? what do I have to do to work?

Probably use Mobile-Detect , identify the device of the visitor (desktop, tablet, smartphone) and just redirect to desktop variant if necessary. Yes, this is the PHP side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM