如何解决防止特定域路径的 Gatsby 页面出现在 Google 搜索中
是否可以阻止特定域路径的 Gatsby 页面出现在 Google 搜索中。
我不想阻止整个网站出现在 Google 搜索中,只阻止某个页面出现在特定路径中。例如www.mywebsite.co.uk/hide-me
解决方法
使用 <Helmet>
组件设置漫游器元标记。
const HideMe = ()=>{
return <>
<Helmet>
<meta name={`robots`} content={`noindex,nofollow`} />
</Helmet>;
<h1>I'm the Hide Me page </h1>
</>;
大多数 Gatsby starter 都带有一个 SEO
组件,其中包含机器人 meta
标记等内容,如果是这种情况,您可能需要为每个传递正确的页面自定义它prop
。例如:
const SEO = ({ index,follow,description,lang,meta,title }) => {
const { site } = useStaticQuery(graphql`
query getAllMetadata {
site {
siteMetadata {
title
description
author
}
}
}
`,);
const metaDescription = description ?? site.siteMetadata.description;
return <Helmet htmlAttributes={{ lang }} title={title} titleTemplate={`%s | ${site.siteMetadata.title}`}>
<meta name={`robots`} content={`${index ? `index`:`noindex`},${follow ? `follow`:`nofollow`}`}/>
<meta name={`description`} content={metaDescription}/>
<meta name={`og:title`} content={title}/>
<meta name={`og:description`} content={metaDescription}/>
<meta name={`og:type`} content={`website`}/>
<meta name={`twitter:card`} content={`summary`}/>
<meta name={`twitter:creator`} content={site.siteMetadata.author}/>
<meta name={`twitter:title`} content={title}/>
<meta name={`twitter:description`} content={metaDescription}/>
</Helmet>;
};
注意:我假设 index
和 follow
都是布尔值,但可以根据需要对其进行自定义或更适合您的任何内容
如果是这种情况,在您的 /hide-me
页面中,您会看到如下内容:
const HideMe = ()=>{
return <>
<SEO index={false} follow={false} />
<h1>I'm the Hide Me page </h1>
</>;
此外,您需要向指向该页面的所有链接添加 rel
属性 nofollow
以避免被 Google 的抓取工具跟踪。
<Link rel={`nofollow`} to={`/hide-me`}>Untracked link</Link>
此外,您可能还想从 sitemap.xml
(如果有)文件中删除该页面,您可以使用其中一个站点地图插件(如 gatsby-plugin-sitemap
)轻松实现它,该插件随附使用 exclude
规则。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。