views:

113

answers:

2

Given a URL like:

before: http://feeds.wsjonline.com/~r/wsj/health/feed/~3/felKuQPa41U/ which redirects eventually to: after: http://blogs.wsj.com/health/2009/08/14/insurance-salesman-to-obama-why-are-you-vilifying-insurers/

Using Coldfusion, how can I obtain that final (after) URL? I believe CFHTTP will redirect automatically up to 4 times, but I can't find a way to obtain that final redirected URL.

ideas? thxs

+6  A: 

Searching Google may help, sometimes. http://www.bennadel.com/blog/934-Ask-Ben-Handling-Redirects-With-ColdFusion-CFHttp.htm

Havenard
Thanks for the link, sadly that example doesn't work for all URLS, its very spotty.
AnApprentice
A: 

if you get a redirect with cfhttp you have two options. 1) you can follow (as you say, up to 4 of them in a row). You could also handle them manually by not following them and checking the location variable of the result. THe code would be something like this (note that this is psudo-coldfusion, my syntax might be off:

<cfset lastgoodURL = "http://bar.com" />
<cfset foo = false />

<cfloop while="foo eq false">
   <cfhttp url="#lastgoodURL#" redirect="false" name="baz" />
   <cfif length(baz.responseHeader.Location) eq 0>
     <cfbreak />
   </cfif>
   <cfset lastgoodURL = baz.responseHeader.Location />
</cfloop>
ryber