If I\'m in an RHTML view in Rails, it is easy to URL-escape something:
\">Foo
CGI.escape will do it:
<% redirect_href = "/redirect?#{CGI.escape target}&foo=bar&baz=some_other_stuff" -%> Foo