jtrupiano / rack-rewrite

A web server agnostic rack middleware for defining and applying rewrite rules. In many cases you can get away with Rack::Rewrite instead of writing Apache mod_rewrite rules.
http://github.com/jtrupiano/rack-rewrite
MIT License
836 stars 80 forks source link

Use subdomain string as a part of redirection url #80

Open gabyshev opened 8 years ago

gabyshev commented 8 years ago

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
marcosgz commented 8 years ago

maybe something like:

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