2

I want to make a rewrite to another domain so that http://domain1.com/abc would point to http://domain2.com/xyz. This is my code:

require 'rack/rewrite'
config.middleware.insert_before(Rack::Lock, Rack::Rewrite) do
  rewrite '/abc', 'http://domain2.com/xyz'
end

But after I open http://domain1.com/abc, Im being pointed to http://domain1.com/http:/domain2.com/xyz . How could I rewrite it so that it would point to the right place?

sNiCKY
  • 1,823
  • 3
  • 18
  • 20

1 Answers1

1

You need to use a redirect for this, not a rewrite. Rewrites just change the URL that your app sees whilst redirects do an actual HTTP 301.

require 'rack/rewrite'
config.middleware.insert_before(Rack::Lock, Rack::Rewrite) do
  r301 '/abc', 'http://domain2.com/xyz'
end
jordelver
  • 8,292
  • 2
  • 32
  • 40