Forum Moderators: coopster

Message Too Old, No Replies

Getting redirected URL

getting forwarded/redirected rul with php

         

greg25

7:41 pm on Nov 7, 2008 (gmt 0)

10+ Year Member



Hi,

I'm looking for a script to get the redirected URL.

For example:
- original url: http://www.example.com/rt.php?vd=imd0030382-0
- the redirected url: [us.example2.com...]

I would need the url in a php variable...

Any ideas?

[edited by: eelixduppy at 8:53 pm (utc) on Nov. 7, 2008]
[edit reason] exemplified [/edit]

mooger35

9:41 pm on Nov 7, 2008 (gmt 0)

10+ Year Member



$url = 'http://us.example2.com/title/tt0029843/';

header [ca3.php.net]("location:$url");

greg25

1:35 am on Nov 8, 2008 (gmt 0)

10+ Year Member



Hi,

What I meant was is that I have a variable:
$url1 = 'http://www.example.com/rt.php?vd=imd0030382-0'

(http://www.example.com/rt.php is hosted on a different server and this page is redirect to a new url: [us.example2.com...]

How cam I get the new url into a variable? (url2 = 'http://us.example2.com/title/tt0029843/'; )

Anyango

5:53 am on Nov 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So You want to stay on your page and study this page 'http://www.example.com/rt.php?vd=imd0030382-0' and want to extract the url that page will redirect to ? You have to parse HTTP headers .

See [php.net...]

$headers=get_headers('http://www.example.com/rt.php?vd=imd0030382-0', 1);
print_r($headers);

greg25

12:25 pm on Nov 8, 2008 (gmt 0)

10+ Year Member



So for get_headers I got the following response:
Array
(
[0] => HTTP/1.1 200 OK
[Date] => Sat, 08 Nov 2008 12:02:56 GMT
[Server] => Apache
[X-Powered-By] => PHP/5.2.1
[Expires] => Wed, 1 Jan 2007 05:00:00 GMT
[Last-Modified] => Sat, 08 Nov 2008 12:02:56 GMT
[Cache-Control] => Array
(
[0] => no-store, no-cache, must-revalidate
[1] => post-check=0, pre-check=0
)

[Pragma] => no-cache
[Content-Length] => 172
[Connection] => close
[Content-Type] => text/html
)

how do I get the second URL from this? (url2 = 'http://us.example2.com/title/tt0029843/'; )

Anyango

1:38 pm on Nov 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think then the second page is redirecting using .htaccess Mod Rewrite, and not a normal redirect using programming language. If anyone can tell us how to track that redirect ? i am also interested in knowing the answer to that. Because the above array seems to be generated by the Final Page as it is sending 200 OK, i am sure it was mod rewrite that handled the url.