使用rel=alternate ,和rel=canonical进行网站优化

本文介绍了在PC站和移动站中使用rel='alternate'和rel='canonical'标签的原因和方法,旨在帮助搜索引擎理解两个站点的对应关系,避免重复内容问题。在PC站中,添加rel='alternate'链接到移动站;在移动站中,添加rel='canonical'链接回PC站。当拥有独立的桌面和移动网站时,应使用绝对路径确保URL正确,且在多个页面情况下需对应添加这些标签。响应式网站则不需要使用此技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先为什么要在PC站(rel="alternate")和移动站(rel="canonical")使用该标签,该标签的作用是什么。

当你拥有独立的PC站和移动站点时,即需要使用该标签,每个PC页面只能有一个移动对应页面,反之亦然。

如何使用:

在PC站点当中,在</head>前加入

<link rel="alternate" href="http://m.abc.com/">

在对应的移动站点中</head>前加入

<link rel="canonical" href="http://www.abc.com/">

 

以上两者关系为互指关系,意思是告诉搜索引擎,我这两个页面是对应的关系,以帮助他们了解向其用户提供的网站以及防止出现重复内容问题。

切记URL书写时要写成绝对路径,即使它不符合链接标记的规范,但一般的共识是在定义rel属性时不使用相对URL。相对URL更有可能被搜索引擎解释为错误。相同的最佳实践适用于链接标记的其他用途:规范URL,href、lang属性和分页属性。

多个页面的情况下使用:

//PC站:

<link rel="alternate" href="http://m.abc.com/">

<link rel="alternate" href="http://m.abc.com/about/">

<link rel="alternate" href="http://m.abc.com/news/1.html">

//移动站:

<link rel="canonical" href="http://www.abc.com/">

<link rel="canonical" href="http://www.abc.com/about/">

<link rel="canonical" href="http://www.abc.com/news/1.html">

如果你有响应式网站,则无需使用该标签。只有在不同的URL上有单独的桌面和移动网站时,才会使用该属性。

<!doctype html> <html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>汉的解释|汉的意思|汉典“汉”字的基本解释</title> <meta name="title" content="汉的解释|汉的意思|汉典“汉”字的基本解释"> <meta name="keywords" content="左:氵,右:又。" /><meta property="og:title" content="“汉”字的解释 | 汉典" /> <meta property="og:image" content="//www.zdic.net/images/logo-zh-cn.png" /> <meta property="og:description" content="“汉”字的解释,释义,异体字,音韵方言,部首笔画,康熙字典,说文解字,字源字形" /> <meta name="description" content="“汉”字的解释,释义,异体字,音韵方言,部首笔画,康熙字典,说文解字,字源字形" /> <meta property="og:url" content="//www.zdic.net/hans/汉" /> <link rel="canonical" href="//www.zdic.net/hans/汉" /> <link rel="alternate" hreflang="x-default" href="//www.zdic.net/hans/汉" /> <link rel="alternate" hreflang="zh-Hans" href="//www.zdic.net/hans/汉" /> <link rel="alternate" hreflang="zh-Hant" href="//www.zdic.net/hant/汉" /> <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" /> <meta name="apple-mobile-web-app-title" content="汉典" /> <meta name="theme-color" content="#8b411c" /> <!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-161009-3"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-161009-3'); </script> <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5789084355642416" crossorigin="anonymous"></script> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?3df9beb4da8d56b1d05ad32a8e6cf208"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <link type="text/css" rel="stylesheet" media="screen" href="/style.css" /
最新发布
03-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值