I need to be able to rewrite non www to www but NOT in the case when there is a (non www) subdomain present.
so example.com to-> www.example.com but sub.example.com remains sub.example.com
I'm in rails 3 and it seems this should be accomplished using Rack Middleware, but the snag is this is a multitenant app so the TLD could potentially be any domain.
This is where I am so far:
Class Www
def initialize(app)
@app = app
end
def call(env)
request = Rack::Request.new(env)
if !request.host.starts_with?("www.")
[301, {"Location" => request.url.sub("//","//www.")}, self]
else
@app.call(env)
end
end
def each(&block)
end
end
Any pointers would be appreciated....