停止搜索引擎为页面的特定部分建立索引 [英] Stop search engines to index specific parts of the page

查看:81
本文介绍了停止搜索引擎为页面的特定部分建立索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php页面,可以渲染一本书,比如说100页.每个页面都有一个特定的网址(例如/my-book/page-one/my-book/page-two等).

I have a php page that renders a book of let's say 100 pages. Each page has a specific url (e.g. /my-book/page-one, /my-book/page-two etc).

翻转页面时,我使用 url.js 使用历史API更改了网址.

When flipping the pages, I change the url using the history API, using url.js.

由于所有书籍的内容都是从服务器端呈现的,所以问题在于内容是由搜索引擎索引的(特别是我指的是Google),但是网址错误(例如,它在,但网址为page-one).

Since all the book content is rendered from the server side, the problem is that the content is indexed by search engines (especially I'm referring to Google), but the urls are wrong (e.g. it finds a snippet on page-two but the url is page-one).

如何停止搜索引擎(至少是Google)对页面上的所有内容建立索引,而仅对可见图书页面建立索引?

How to stop search engines (at least Google) to index all the content on the page, but index only the visible book page?

如果我以不同的方式呈现内容,例如<div data-page-number="1" data-content="Lorem ipsum..."></div>然后在JavaScript端以所需的格式进行更改,是否可以工作?这会使页面变慢,实际上我不确定Google是否不会通过JavaScript为更改的内容编制索引.

Would it work if I render the content in a different way: for example, <div data-page-number="1" data-content="Lorem ipsum..."></div> and then on the JavaScript side to change that in the needed format? That would make the page slower and in fact I'm not sure if Google will not index the changed content by JavaScript.

代码如下:

<div data-page="1">Page 1</div>
<div data-page="2">Page 2</div>
<div data-page="3" class="current-page">Page 3</div>
<div data-page="4">Page 4</div>
<div data-page="5">Page 5</div>

然后唯一可见的div是.current-page之一.相同的内容会在多个URL上提供,因为这是必需的,以便用户可以在页面之间切换.

Then only visible div is the .current-page one. The same content is served on multiple urls because that's needed so the user can flip between pages.

例如,/book/page/3将呈现这段HTML,而/book/page/4呈现相同的事物,唯一的区别是添加到第4个元素的current-page类.

For example, /book/page/3 will render this piece of HTML while /book/page/4 renders the same thing, the only difference being the current-page class which is added to the 4th element.

Google确实为不同的URL编制了索引,但是这样做的确是错误的:例如,片段Page 5链接到/book/page/2,从而呈现给用户Page 2(而不是Page 5).

Google did index different urls, but it did it wrong: for example, the snippet Page 5 links to /book/page/2 which renders to the user Page 2 (not Page 5).

如何告诉Google(和其他搜索引擎)我只想对.current-page中的内容编制索引?

How to tell Google (and other search engines) I'm only interested to index the content in the .current-page?

推荐答案

将内容保存在JSON文件中,您不能在HTML中对其进行渲染.在服务器上,仅提供正确的页面:对用户可见的内容.

Save the content in a JSON file which you do not render in the HTML. From the server, serve only the correct page: the content which is visible to the user.

当用户单击按钮(上一页/下一页链接等)时,使用JavaScript渲染您具有JSON文件的内容,然后像执行操作一样更改url.

When the user clicks the buttons (prev/next page links etc), render using JavaScript the content you have the JSON file and change the url like you're already doing.

这样一来,您就知道自己始终从服务器提供正确的内容,而Google机器人显然会正确索引页面.

That way you know you always serve from the server the right content and the Google bot will obviously index the pages correctly.

这篇关于停止搜索引擎为页面的特定部分建立索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆