View Full Version : redirect 302 help

05-04-2011, 05:42 PM
I am trying to get a simple php/jsp that can read an ip address and redirect to it.

For example: a person has a link: http://subdomain.domain/filename > this needs to go to the ipaddress displayed on this page (http://xx.x.x.x.x/filename ) this page has a value redirect=ipaddress (so the new url would be http:// ip address/filename. The Ip address is the value which is returned from the loadbalancer and can change.

I would like to use the information on this page which is the redirect="ipaddress". Do i need to do this in php or .htaccess file or a rewrite?

$var =('http://ipaddress/filename');exit();?>

Thanks for your help

05-04-2011, 07:43 PM
You can do either, though I would opt for PHP.

One thing you need to consider is that someone might use your 'redirect' script to redirect users to another site, for instance from a spam email. If your redirect script gets used heavily, you can get your domain in some blacklists.

As for redirecting:

$file = $_SERVER['REQUEST_URI'];
$file = substr($file, 0, strpos($file,'?'));

header('Location: http://'.$ip.$file);

Not sure how you are getting the ip address from.