Created
January 20, 2012 22:02
-
-
Save neotericdesign/1649848 to your computer and use it in GitHub Desktop.
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
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 |
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
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