rack-rewrite icon indicating copy to clipboard operation
rack-rewrite copied to clipboard

Use subdomain string as a part of redirection url

Open gabyshev opened this issue 8 years ago • 1 comments

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

gabyshev avatar Jul 12 '16 13:07 gabyshev

maybe something like:

r301 %r{^(/audio/(.*)}, lambda { |match, rack_env|
  subdomain = rack_env['SERVER_NAME'].split('.')[0]
  "http://mysite.com/#{subdomain}/audio/#{match[1]}"
}

marcosgz avatar Jul 15 '16 21:07 marcosgz