Created
February 4, 2010 01:18
-
-
Save danielberlinger/294267 to your computer and use it in GitHub Desktop.
Special case robots.txt as Rails Metal
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
# Allow the metal piece to run in isolation | |
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails) | |
class Robots | |
def self.call(env) | |
if env["PATH_INFO"] =~ /^\/robots.txt/ | |
return disallow_multimedia if env["HTTP_HOST"] == 'www.something.biz' || env["HTTP_HOST"] =='something.biz' | |
return disallow_everything if env["HTTP_HOST"] =~ /\w*\.something.biz/ | |
return disallow_everything if env["HTTP_HOST"] =~ /\w*\.somethingelse.com/ | |
allow_everything | |
else | |
[404, {"Content-Type" => "text/html"}, ["Not Found"]] | |
end | |
end | |
def self.disallow_everything | |
[200, {"Content-Type" => "text/plain"}, ["User-Agent: *\nDisallow: /"]] | |
end | |
def self.disallow_multimedia | |
[200, {"Content-Type" => "text/plain"}, ["User-Agent: *\nDisallow: /multimedia"]] | |
end | |
def self.allow_everything | |
[200, {"Content-Type" => "text/plain"}, ["User-Agent: *\nAllow: /"]] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment