On the "ugly URL page" you put <link rel="canonical" href="www.mysite.com/id/pretty_title">
which tells the search engine your preferred URL for that content.
Can also set www.mysite.com/id/?some_ugly_parameters_to_let_me_know_what_search_it_is_from
to have a 301 redirect
to your pretty URL
Canonical URLs: https://support.google.com/webmasters/answer/139066
301 Redirects: https://support.google.com/webmasters/answer/93633?hl=en