A platform for community discussion. Free, open, simple.
FEATURE: let Google index pages so it can remove them
Sam Saffronbb4e8899c418
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex 7abf1f36596..abde04d24be 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -806,7 +806,13 @@ class ApplicationController < ActionController::Baseenddef add_noindex_header- response.headers['X-Robots-Tag'] = 'noindex' if request.get?+ if request.get?+ if SiteSetting.allow_index_in_robots_txt+ response.headers['X-Robots-Tag'] = 'noindex'+ else+ response.headers['X-Robots-Tag'] = 'noindex, nofollow'+ end+ endendprotecteddiff --git a/app/views/robots_txt/no_index.erb b/app/views/robots_txt/no_index.erbindex 7697afcf260..a02cc1b1f5d 100644--- a/app/views/robots_txt/no_index.erb+++ b/app/views/robots_txt/no_index.erb@@ -1,4 +1,13 @@# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file#++# Googlebot must be allowed to index so it can remove items from the index+# we return the X-Robots-Tag with noindex, nofollow which will ensure+# indexing is minimized and nothing shows up in Google search results+User-agent: googlebot+Allow: <%= Discourse.base_uri + "/" %>+Disallow: <%= Discourse.base_uri + "/uploads/*" %>+User-agent: *Disallow: <%= Discourse.base_uri + "/" %>+diff --git a/spec/requests/robots_txt_controller_spec.rb b/spec/requests/robots_txt_controller_spec.rbindex c15297ff11d..16327997c9c 100644--- a/spec/requests/robots_txt_controller_spec.rb+++ b/spec/requests/robots_txt_controller_spec.rb@@ -132,6 +132,7 @@ RSpec.describe RobotsTxtController doget '/robots.txt'expect(response.body).to_not include("Disallow: /u/")+ expect(response.body).to include("User-agent: googlebot\nAllow")endit "returns overridden robots.txt if the file is overridden" dodiff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex b4d157d536f..b2c9b5ebdae 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -1853,7 +1853,7 @@ RSpec.describe TopicsController doget "/t/#{topic.slug}/#{topic.id}.json"- expect(response.headers['X-Robots-Tag']).to eq('noindex')+ expect(response.headers['X-Robots-Tag']).to eq('noindex, nofollow')endit "doesn't store an incoming link when there's no referer" do