用于图像加载的Ajax导致404错误 [英] Ajax used for image loading causes 404 errors

查看:143
本文介绍了用于图像加载的Ajax导致404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个页面,其中包含超过1000张图像,每页仅显示10张图像,当人们看到图像"时,也使用数据表加载了ajax. 一切正常,但是在Google网站管理员工具中,我仅收到数千个404错误,页面如下: http://example.com/ajax/%5C%22http:%5C/%5C/example.com%5C/image%5C/1937%5C/image-name%5C%22 当然,如果我转到此页面,则会收到404错误,因为不存在这样的页面,但是我不明白为什么Google会提取这样的URL. 卡片网址如下所示:example.com/image/此处为4位数字/图像名称

We have a page with over 1000 image, we show only 10 on each page, we load them with ajax, when people "see the images", also using datatable. Everything works fine, however in Google webmaster tools, I just got thousands of 404 errors, with pages like this: http://example.com/ajax/%5C%22http:%5C/%5C/example.com%5C/image%5C/1937%5C/image-name%5C%22 Of course if I go to this page, I get a 404 error, because no page like this exists, but I don't understand then why Google fetches URLs like this. A card url looks like this: example.com/image/a 4 digit number here/image-name

当它加载了ajax时,它会创建这种url,您(作为访问者)不会看到,但Google会以某种方式获取它.

As it gets loaded with ajax it creates that kind of url, which you (as a visitor) never sees but somehow Google fetches it.

现在我将/ajax添加到robots.txt中以禁止获取它,但是我不确定这是否是最好的主意.

Now I added /ajax to robots.txt to disallow fetching it, but I'm not sure if that's the best idea.

任何帮助将不胜感激.

推荐答案

最可能的原因是您的ajax目录(以及其他可能的目录)可读并且列出了您的PHP文件,Google可以访问并解析这些文件以获取更多URL.

The most likely reason is that your ajax directory (and possible other directories) is readable and lists your PHP files, which Google can access and parse for more URLs.

例如,如果您的脚本之一使用以下字符串回显JSON,则Google会找到

For example, if one of your scripts echos JSON with strings like the following, Google will find

<a class=\"quality1\" href=\"http:\/\/example.com\/card\/22\/inner-rage\">

,然后尝试导航到解析为该链接的链接

and try to navigate to that link which resolves to

http://example.com/%22http:////example.com//card//22//inner-rage/%22

是404.

您应停止 http://example.com/ajax/使用.htaccess,或在其中放置一个空的index.html.

You should stop http://example.com/ajax/ from displaying directory contents with either an .htaccess, or drop an empty index.html there.

您还禁止在robots.txt中使用/ajax,因此这也应该起作用.两者都尝试.

You've also disallowed /ajax in your robots.txt, so this should also work. Try both.

这篇关于用于图像加载的Ajax导致404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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