Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8295853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:45:17+00:00 2026-06-08T14:45:17+00:00

I need to redirect to some 3rd party websites. The issue is that some

  • 0

I need to redirect to some 3rd party websites. The issue is that some of the urls works to redirect and some doesn’t work, using redirect_to url

Example 1:
http://example.com/click?a(9999999)p(9999999)prod(999999)ttid(999)url(http%3A%2F%2Fwww.someothersite.se%2Fd%2FBLah-Fooo%2FBar%2F_%2FA-3z324qaF1z140nu%3FNr%3D234234234)

With this URL I just do: redirect_to url

Example 2:
http://click.example.com/c/9999/m/9999/t/a/9999/?url=http://www.someothersite.se/sv/foo/bar/baz-99/foo-bar-baz-9999?tm=999999

When using: redirect_to url
I get ERROR URI::InvalidURIError: bad URI(is not URI?)

So, I tried to just do:
redirect_to URI.encode(url)
… and it works! But then the URL in example 1 is not working anymore. Says the site is not found. No error in Rails though.

So, I need an approach that works with both (all?) URIs. Any ideas?

Using Ruby 1.9.3 and Rails 3.2.5

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T14:45:19+00:00Added an answer on June 8, 2026 at 2:45 pm

    Solved it like this:

    uri = URI.parse(the_url)
    redirect_to uri.to_s
    rescue URI::InvalidURIError => encoding
      redirect_to URI.encode(the_url)
    

    Works for my app so far.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to redirect some urls. Formerly I had http://mysite.com/foobar/?section_id=1234 These are no pointing
I need to redirect some output that would normally be printed to screen into
I need to redirect some of my html pages to corresponding php pages. That
I need to redirect some of the older pages in my application to new
I need to permanent redirect some pages, and redirect the user to the new
I need some advice on techniques to perform page redirect in asp.net. Which one
I need some help on mod rewrite 301 , to redirect my old website
I need to redirect all urls with matching keyword, regardless of position in link,
I need to redirect if the user is accessing the site using Chrome OS
I've changed some settings in my website, and now I need to redirect from:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.