Created
March 27, 2018 22:06
-
-
Save veganstraightedge/0825ba20fc6f413b5e1b32c9485bb339 to your computer and use it in GitHub Desktop.
Redirect `app.any-domain.tld` to `any-domain.tld` while keeping the path in place.
This file contains hidden or 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
module Rack | |
class AppRedirect | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
request = Rack::Request.new(env) | |
if request.host.start_with?("app.") | |
location = request.scheme + "://" + request.host.sub("app.", "") + request.path | |
return redirect(location) | |
end | |
@app.call(env) | |
end | |
private | |
def redirect(location) | |
[ | |
301, | |
{ "Location" => location, "Content-Type" => "text/html" }, | |
["Moved Permanently"] | |
] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment