Skip to content

Instantly share code, notes, and snippets.

@neotericdesign
Created January 20, 2012 22:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neotericdesign/1649848 to your computer and use it in GitHub Desktop.
Save neotericdesign/1649848 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)
#
#
#
# CHANGE THE PRODUCTION DOMAIN WHERE IT SAYS PRODUCTION_DOMAIN_HERE
#
#
#
if request.host =~ /^PRODUCTION_DOMAIN_HERE.com/
[301, {"Location" => request.url.sub("//", "//www.")}, self]
else
@app.call(env)
end
end
def each(&block)
end
end
config.autoload_paths += %W(#{config.root}/lib)
config.middleware.use "CanonicalRedirect" # add inside class Application < Rails::Application
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment