Tuesday 17 June 2008

pull from another site

Recently a site I was working on needed to forward all unknown requests to another website (their old website). This turned out to be shockingly easy to do!

In the Application Controller:

  def default
logger.debug("request.env[\"REQUEST_URI\"] #{request.env["REQUEST_URI"]}")
render :text => Net::HTTP.get_response(
"www.oldsite.com",
request.env["REQUEST_URI"]
).body
end



And at the very bottom (so it is only done if nothing else catches the route):

  map.connect '*path' , :controller => 'application' , :action => 'default'



Easy peasy!

No comments: