Reputation: 6125
I want to redirect to any given URL. I am trying this:
Route:
get 'track/*redirect_url', to: 'tracker#track'
Controller:
redirect_to params[:redirect_url]
However when I visit tracker URLs - I am getting strange redirects:
http://localhost:3000/http://google.com/search=xyz
=> http:/google.com/search=xyz
(one slash is missing!)
http://localhost:3000/http://google.com
=> http:/google
(slash + .com is missing"
Rails is apparently somehow transforming URL parts but since I do not have a control over it - I need a way to fix it.
Any ideas how?
Upvotes: 0
Views: 352
Reputation: 211
It happens because rails tries to parse that as a single url and fails because of escaping (// is parsed as "escaped /").
Also what happens to .com
- it's parsed by rails as format (like .html or .json).
I would suggest you doing it with URL encoding and query-string params, eg:
http://localhost:3000/track/?redirect_url=https%3A%2F%2Fgoogle.com
Upvotes: 1