Opened 12 years ago
Closed 12 years ago
#18351 closed New feature (fixed)
Sitemaps should use the X-Robots-Tag HTTP header
Reported by: | Mike Lissner | Owned by: | Mike Lissner |
---|---|---|---|
Component: | contrib.sitemaps | Version: | 1.4 |
Severity: | Normal | Keywords: | decorator, sitemap.xml, robots |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Major search engines currently support three ways that they can be blocked:
- On an HTML page you can provide a meta robots tag that says nocrawl or noindex (or both)
- You can provide an HTTP X-Robots tag that says nocrawl or noindex (or both)
- You can list a file in your robots.txt file.
The distinction between nocrawl, robots and noindex is subtle but important.
*Nocrawl* means that crawlers should stay out -- not even visit the page. Robots.txt and the nocrawl tags accomplish this. Contrary to the *extremely* common belief, placing a resource in robots.txt or putting a nocrawl meta tag on it will *not* prevent it from showing up in search results. The reason is that if Google or Bing knows about a page, that page will show up in search results until it is looked into further. Later, when that happens, the crawler will detect if it's blocked by robots.txt or by norobots. If so, it won't crawl the page (as requested), *but* the page will continue to be in search results unless there's a *noindex* flag.
Here's a short video from Matt Cutts (Google employee) explaining this oddity: http://www.youtube.com/watch?v=KBdEwpRQRD0
And Microsoft has it documented here: http://www.bing.com/community/site_blogs/b/webmaster/archive/2009/08/21/prevent-a-bot-from-getting-lost-in-space-sem-101.aspx
*Noindex* means to please crawl the page, but to not include it in the index, and we should be using this on our sitemaps. Since we don't currently use the noindex HTTP headers, sitemaps made with Django will appear in search results even though they're pretty much useless. You can see see this with clever searches on google for things like [ sitemap.xml site:django-site.com ].
This oddity causes an additional problem because the only way to prevent a page from appearing in Bing or Google is currently:
- to include it in your sitemap so that it will be crawled as soon as possible; and
- to place a noindex tag on the page or resource itself.
The site I run has strict requirements when it comes to this fun topic, and there's a lot of people that believe robots.txt works, so I've written up my finding on this: http://michaeljaylissner.com/blog/respecting-privacy-while-providing-hundreds-of-thousands-of-public-documents
I'll write up a patch (my first) to fix this, and will submit it shortly.
Attachments (1)
Change History (11)
comment:1 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:2 by , 12 years ago
Has patch: | set |
---|
by , 12 years ago
Attachment: | add_http_tag.diff added |
---|
Removed noimageindex, which doesn't make sense in this context.
comment:3 by , 12 years ago
Re-read over this, and figured I'd better summarize: This patch makes is so Django sitemaps don't appear in search results.
comment:4 by , 12 years ago
Triage Stage: | Unreviewed → Ready for checkin |
---|
comment:5 by , 12 years ago
This is marked as ready for checkin. Is there anything I need to do to get this pushed into core?
comment:6 by , 12 years ago
Has patch: | unset |
---|---|
Keywords: | decorator sitemap.xml robots added |
may be this decorator?
from django.utils.functional import wraps def x_robots_tag(func): def inner(request, *args, **kwargs): responce = func(request, *args, **kwargs) responce['X-Robots-Tag'] = 'noindex, noodp, noarchive' return responce return wraps(func)(inner) url('^sitemap\.xml$', x_robots_tag(index), {'sitemaps': sitemaps}),
comment:7 by , 12 years ago
Triage Stage: | Ready for checkin → Accepted |
---|
Tests are missing (trivial). And I don't understand why you transformed the TemplateResponse
in an HttpResponse
? What problem does it solve?
comment:8 by , 12 years ago
Component: | Core (Other) → contrib.sitemaps |
---|
comment:9 by , 12 years ago
Has patch: | set |
---|
I've created a branch containing tests and a fix based on the suggested use of a decorator.
comment:10 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
I've added a patch to implement the above. Would love review.