Skip to content

Instantly share code, notes, and snippets.

@DCarper
Created December 14, 2010 20:24
Show Gist options
  • Select an option

  • Save DCarper/741029 to your computer and use it in GitHub Desktop.

Select an option

Save DCarper/741029 to your computer and use it in GitHub Desktop.
class CanonicalRedirect
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
if request.host =~ /^domain1/
[301, {"Location" => request.url.sub("//domain1", "//www.domain2")}, self]
elsif request.host =~ /^domain2/
[301, {"Location" => request.url.sub("//", "//www.")}, self]
elsif request.host =~ /^www.domain1/
[301, {"Location" => request.url.sub("//www.domain1", "//www.domain2")}, self]
else
@app.call(env)
end
end
def each(&block)
end
end
def each(&block)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment