From 43503921db19d3309e3bc29de8b41f8ef1bbcaf6 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 26 May 2024 16:15:23 +0100 Subject: [PATCH] Ensure random redirects aren't indexed Still allow them to be followed --- website/common/models.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/website/common/models.py b/website/common/models.py index cfb24ab..f560c06 100644 --- a/website/common/models.py +++ b/website/common/models.py @@ -299,8 +299,10 @@ class BaseListingPage(RoutablePageMixin, BaseContentPage): def random(self, request: HttpRequest) -> HttpResponse: page = self.get_listing_pages().order_by("?").first() if page is None: - return redirect(self.get_url(request=request), permanent=False) - return redirect(page.get_url(request=request), permanent=False) + response = redirect(self.get_url(request=request), permanent=False) + response = redirect(page.get_url(request=request), permanent=False) + response.headers["X-Robots-Tag"] = "noindex" + return response class ListingPage(BaseListingPage):