JavaScript 重定向会导致搜索引擎出现不需要的结果

发布于 2024-11-05 06:16:39 字数 314 浏览 0 评论 0原文

我有一个 HTML5 演示网站 (http://html5beats.com/),它使用 JavaScript 来检测某些 HTML5 功能。如果这些功能不存在,我会重定向到“请更改或升级您的浏览器”页面,因为它们对于网站的正常运行至关重要。

问题是一些搜索引擎(特别是谷歌)似乎遵循重定向。这会导致“不支持您的浏览器”消息成为我网站的主要搜索结果。

我是否错误地使用了 JavaScript 重定向?我可以做些什么来告诉 Google 和其他搜索引擎哪个页面包含主要网站内容?

I have an HTML5 demo site (http://html5beats.com/) that uses JavaScript to detect certain HTML5 features. I do a redirect to a "please change or upgrade your browser" page if those features are not present, since they are critical to making the site work.

The problem is that some search engines (specifically Google) seem to follow the redirect. This results in a nasty "Your Browser is Not Supported" message as the main search result for my site.

Am I using JavaScript redirects incorrectly? Is there something I can do to tell Google and other search engines which page has the main site content?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

×眷恋的温暖 2024-11-12 06:16:39

首先,您应该使用 robots.txt 告诉搜索引擎您不想列出的网页:

其次,您还可以向 Google 提供帮助(和其他搜索引擎)通过提供站点地图来了解您的网站:

第三,您还可以考虑一种快速而肮脏的方法来捕获 Google 机器人(以及其他网络抓取工具) )通过 JavaScript 中的 navigator.userAgent 属性并防止在这些情况下重定向:

在最后一种情况下,不要直接比较 navigator.userAgent 字符串。相反,使用 indexOf 在用户代理字符串中查找标识 URL,例如:

function upgradeRedirect() {
 if (navigator.userAgent.indexOf("http://www.google.com/bot.html") != -1) return;
 document.location.href = 'upgrade.html';
}

First, you should use robots.txt to tell search engines those pages that you don't want listed:

Second, you can also provide assistance to Google (and other search engines) in understanding your site by providing a sitemap:

Third, you can also consider a quick-and-dirty method of catching the Google bot (and other web crawlers) through the navigator.userAgent property in JavaScript and preventing the redirect in those cases:

In the last case, don't do a direct comparison of the navigator.userAgent string. Rather, use indexOf to find the identifying URL in the user-agent string, e.g.:

function upgradeRedirect() {
 if (navigator.userAgent.indexOf("http://www.google.com/bot.html") != -1) return;
 document.location.href = 'upgrade.html';
}
弄潮 2024-11-12 06:16:39

这实际上取决于您向 Googlebot 提供的内容(考虑到 Googlebot 所抓取的用户代理)。也许更好的策略是使用常规标题标签等加载常规内容,然后如果用户不支持 html5,并提供一些下载 html5 浏览器的链接,则在页面上弹出模式对话框。这样,您的列表对于网站来说仍然看起来很受人尊敬:http://html5beats.com/。顺便说一句——我真的很喜欢你的网站/想法。

It really comes down to the content you are serving to Googlebot given the user-agent they are crawling with. Perhaps a better strategy would be to load your regular content with your regular title tag etc. and then pop a modal dialogue over the page if the user doesn't support html5 with some links to download an html5 browser. That way your listing will still look respectable for site:http://html5beats.com/. BTW -- I really like your site/idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文