Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Fix frontend robots.txt (#4186)

zackf1477cc8f0c5
diff --git a/frontend/.gitignore b/frontend/.gitignore
index a094d805f..99b7e598e 100644
--- a/frontend/.gitignore
+++ b/frontend/.gitignore
@@ -27,3 +27,7 @@ src/locales/scripts/wp-locales.json
/.npmrc
/.pnpmfile.cjs
/pnpm-lock.yaml
+
+# To prevent accidentally adding a hardcoded robots.txt, see
+# /src/server-middleware/robots.js for the robots.txt file.
+src/static/robots.txt
diff --git a/frontend/src/server-middleware/robots.js b/frontend/src/server-middleware/robots.js
index 7cf240539..8750a4b8f 100644
--- a/frontend/src/server-middleware/robots.js
+++ b/frontend/src/server-middleware/robots.js
@@ -1,5 +1,24 @@
const { LOCAL, PRODUCTION } = require("../constants/deploy-env")
+const deniedUserAgents = [
+ "GPTBot",
+ "CCBot",
+ "ChatGPT-User",
+ "Google-Extended",
+ "anthropic-ai",
+ "Omgilibot",
+ "Omgili",
+ "FacebookBot",
+ "Diffbot",
+ "Bytespider",
+ "ImagesiftBot",
+ "cohere-ai",
+]
+
+const aiDisallowRules = deniedUserAgents
+ .map((ua) => `User-agent: ${ua}\nDisallow: /\n`)
+ .join("\n")
+
/**
* Send the correct robots.txt information per-environment.
*/
@@ -7,16 +26,19 @@ export default function robots(_, res) {
const deployEnv = process.env.DEPLOYMENT_ENV ?? LOCAL
const contents =
- deployEnv === PRODUCTION
- ? `# Block search result pages
+ deployEnv !== PRODUCTION
+ ? `# Block search result pages and single result pages
User-agent: *
+Crawl-delay: 10
Disallow: /search/audio/
Disallow: /search/image/
Disallow: /search/
Disallow: /image/
Disallow: /audio/
+
+${aiDisallowRules}
`
- : `# Block crawlers from the staging site
+ : `# Block everyone from the staging site
User-agent: *
Disallow: /
`
diff --git a/frontend/src/static/robots.txt b/frontend/src/static/robots.txt
deleted file mode 100644
index 2739ca440..000000000
--- a/frontend/src/static/robots.txt
+++ /dev/null
@@ -1,35 +0,0 @@
-User-agent: GPTBot
-Disallow: /
-
-User-agent: CCBot
-Disallow: /
-
-User-agent: ChatGPT-User
-Disallow: /
-
-User-agent: Google-Extended
-Disallow: /
-
-User-agent: anthropic-ai
-Disallow: /
-
-User-agent: Omgilibot
-Disallow: /
-
-User-agent: Omgili
-Disallow: /
-
-User-agent: FacebookBot
-Disallow: /
-
-User-agent: Diffbot
-Disallow: /
-
-User-agent: Bytespider
-Disallow: /
-
-User-agent: ImagesiftBot
-Disallow: /
-
-User-agent: cohere-ai
-Disallow: /