Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

html - 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?

question from:https://stackoverflow.com/questions/65938454/adapt-php-web-sites-for-mobile-devices-redirect-to-mobile-subdomain-m

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...