首页 > 解决方案 > 为移动设备调整 PHP 网站:重定向到移动子域“m”

问题描述

我想将 html 桌面页面从“m”子域重定向到 html 移动页面。我相信我必须更改页面中的某些内容,因此我在其他网络平台上找到了一些设置。问题是,不起作用。

在桌面页面中添加此代码(更改链接):

<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" />

在移动页面中添加这个(更改链接):

<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" />

我需要更改 php 中的某些内容吗?我必须做什么才能工作?

标签: phphtmlredirectmobile

解决方案


可能使用Mobile-Detect,识别访问者的设备(台式机、平板电脑、智能手机),并在必要时重定向到台式机变体。是的,这是 PHP 方面。


推荐阅读