Created
October 12, 2012 22:43
-
-
Save deanet/3882067 to your computer and use it in GitHub Desktop.
redirect spree url
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 "NoWww", ['pasarcairo.com', '192.168.0.177'] |
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 NoWww | |
def initialize(app, hosts = []) | |
@app = app | |
@hosts = hosts | |
end | |
def call(env) | |
req = Rack::Request.new(env) | |
if @hosts.nil? or @hosts.empty? or @hosts.include?(req.host) | |
@app.call(env) | |
else | |
url = "http://#{@hosts[0]}" | |
# url << ":#{req.port}" unless req.port == 80 | |
url << "#{req.path}" | |
url << "?#{req.query_string}" unless req.query_string.empty? | |
res = Rack::Response.new | |
res.redirect(url) | |
res.finish | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment