Skip to content

Block search engines from indexing OVS - #1576

Merged
AhtishamShahid merged 2 commits into
masterfrom
issue-12798-noindex-ovs
Aug 19, 2026
Merged

Block search engines from indexing OVS#1576
AhtishamShahid merged 2 commits into
masterfrom
issue-12798-noindex-ovs

Conversation

@AhtishamShahid

@AhtishamShahid AhtishamShahid commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add <meta name="robots" content="noindex, nofollow"> to ui/templates/base.html, inherited by every page on the site (including error pages)
  • Add RobotsTagMiddleware to set the X-Robots-Tag: noindex, nofollow response header on every response, covering pages that don't extend base.html (Django admin, DRF browsable API, etc.)

Fixes mitodl/hq#12798

Phased rollout (see review discussion)

static/robots.txt is intentionally not changed in this PR. Blocking crawling outright (Disallow: /) immediately would prevent Google from ever re-fetching pages to observe the new noindex directive, which would leave already-indexed pages (like the one in the issue's screenshot) stuck in search results indefinitely instead of dropping out.

Plan:

  1. This PR ships noindex only, so search engines can still crawl, see the directive, and drop existing pages from their index.
  2. A follow-up PR will add Disallow: / to robots.txt once existing pages have had time to be recrawled and removed (or sooner, via a manual Search Console removal request for the specific already-indexed URL).

Test plan

  • uv run pytest ui/views_test.py odl_video/ — no new failures (pre-existing local-env failures unrelated to this change, due to missing local Postgres)
  • uv run ruff format --check / uv run ruff check — clean
  • Verified locally via docker compose up: rendered <head> on a live page contains the noindex meta tag; /admin/login/ response has the X-Robots-Tag header

Adds a noindex/nofollow meta tag to base.html (inherited by every
page) and fixes robots.txt, which had an empty Disallow value that
was actually permitting all crawling.

Fixes mitodl/hq#12798
@AhtishamShahid
AhtishamShahid requested a balanced review from Copilot August 11, 2026 08:31
@AhtishamShahid AhtishamShahid self-assigned this Aug 11, 2026
@AhtishamShahid
AhtishamShahid marked this pull request as ready for review August 11, 2026 08:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds site-wide search-engine indexing controls through HTML metadata and crawler directives.

Changes:

  • Adds noindex, nofollow to the application base template.
  • Blocks crawling through robots.txt.
  • Adds regression tests for both directives.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
ui/templates/base.html Adds robots metadata to application pages.
static/robots.txt Disallows crawler access site-wide.
ui/views_test.py Tests metadata rendering.
odl_video/robots_test.py Tests crawler directives.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread ui/templates/base.html
Comment thread static/robots.txt Outdated
Comment thread odl_video/robots_test.py Outdated
- Add RobotsTagMiddleware to set X-Robots-Tag: noindex, nofollow on
  every response, covering pages that don't extend base.html (e.g.
  Django admin), per review feedback.
- Revert static/robots.txt for now: blocking all crawling immediately
  would prevent search engines from ever fetching pages to observe the
  noindex directive, leaving already-indexed pages stuck. Ship noindex
  first; add Disallow: / in a follow-up once existing pages have had
  time to drop out of the index.
- Tighten robots.txt test to an exact content match (dropped for now
  since robots.txt is unchanged in this PR).

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Suppressed comments (1)

odl_video/settings.py:104

  • Place this middleware first in the stack. With the current ordering, SecurityMiddleware can return the default HTTP-to-HTTPS redirect before calling downstream middleware (SECURE_SSL_REDIRECT defaults to True at odl_video/settings.py:48), so that response never receives the promised X-Robots-Tag header. Making this middleware outermost ensures it also decorates responses short-circuited by other Django middleware.
    "odl_video.middleware.RobotsTagMiddleware",

@umar8hassan umar8hassan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks Good 👍

Just make sure to leave a note on the issue that we have deliberately removed the Disallow from robots.txt for now. Maybe open a follow up sub-issue for that.

Comment thread odl_video/settings.py
@AhtishamShahid
AhtishamShahid merged commit f06149a into master Aug 19, 2026
9 checks passed
@AhtishamShahid
AhtishamShahid deleted the issue-12798-noindex-ovs branch August 19, 2026 07:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants