Last active
October 13, 2015 06:58
-
-
Save brentertz/4157181 to your computer and use it in GitHub Desktop.
Disallow site indexing in non-production environments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Disallow site indexing in non-production environments | |
config.middleware.insert_before(::Rack::Lock, '::Rack::Robots') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rack' | |
# Disallow site indexing in non-production environments | |
module Rack | |
class Robots | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
if env['PATH_INFO'] == '/robots.txt' && !([ENV['RAILS_ENV'], ENV['RACK_ENV']].include? 'production') | |
[200, { 'Content-Type' => 'text/plain' }, ["User-Agent: *\nDisallow: /"]] | |
else | |
@app.call env | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Disallow site indexing in non-production environments | |
Rails.application.config.middleware.insert_before(::Rack::Lock, '::Rack::Robots') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can load either via application.rb or robots_initializer.rb