Opened 6 years ago

Closed 5 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


Major search engines currently support three ways that they can be blocked:

  1. On an HTML page you can provide a meta robots tag that says nocrawl or noindex (or both)
  2. You can provide an HTTP X-Robots tag that says nocrawl or noindex (or both)
  3. 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:

And Microsoft has it documented here:

*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 ].

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:

I'll write up a patch (my first) to fix this, and will submit it shortly.

Attachments (1)

add_http_tag.diff (1.8 KB) - added by Mike Lissner 6 years ago.
Removed noimageindex, which doesn't make sense in this context.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 6 years ago by Mike Lissner

Owner: changed from nobody to Mike Lissner
Status: newassigned

comment:2 Changed 6 years ago by Mike Lissner

Has patch: set

I've added a patch to implement the above. Would love review.

Changed 6 years ago by Mike Lissner

Attachment: add_http_tag.diff added

Removed noimageindex, which doesn't make sense in this context.

comment:3 Changed 6 years ago by Mike Lissner

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 Changed 6 years ago by Andrew Godwin

Triage Stage: UnreviewedReady for checkin

comment:5 Changed 6 years ago by Mike Lissner

This is marked as ready for checkin. Is there anything I need to do to get this pushed into core?

comment:6 Changed 6 years ago by agestart@…

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 Changed 6 years ago by Claude Paroz

Triage Stage: Ready for checkinAccepted

Tests are missing (trivial). And I don't understand why you transformed the TemplateResponse in an HttpResponse? What problem does it solve?

comment:8 Changed 5 years ago by Aymeric Augustin

Component: Core (Other)contrib.sitemaps

comment:9 Changed 5 years ago by Tom Mortimer-Jones

Has patch: set

I've created a branch containing tests and a fix based on the suggested use of a decorator.

comment:10 Changed 5 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: assignedclosed

In 66c83dce074b48342dbfd0d9039c76b8949f0833:

Fixed #18351 -- Added X-Robots-Tag header to sitemaps

Thanks Michael Lissner for the report and initial patch, and
Tom Mortimer-Jones for working on the patch.

Note: See TracTickets for help on using tickets.
Back to Top