rack-rewrite
rack-rewrite copied to clipboard
Use subdomain string as a part of redirection url
I'm not sure. Is there a way to get the current subdomain before redirecting?
For example: request url:
abc.mysite.com/audio/song.mp3
And I want it to be redirected here
mysite.com/abc/audio/song.mp3
maybe something like:
r301 %r{^(/audio/(.*)}, lambda { |match, rack_env|
subdomain = rack_env['SERVER_NAME'].split('.')[0]
"http://mysite.com/#{subdomain}/audio/#{match[1]}"
}