user2195984
user2195984

Reputation: 33

Redirect to another site with not standard port (IP:Port)

How can i Redirect to another site with not standard port (IP:Port) on Php or Html?

On php i try to use header('Location: IP:PORT' ); but it doesn't work.

Any tips to fix this?

Upvotes: 0

Views: 7970

Answers (2)

pradeepcep
pradeepcep

Reputation: 932

You should add http:// or // in front of the address to tell PHP that it is an absolute URL.

For example, if you wanted to redirect to 123.123.123.123 on port 8888, you would do something like this:

<?php

header('Location: http://123.123.123.123:8888');

?>

Note:

It is usually recommended that you use // and not specify http:// explicitly.

Using // makes sense(only?) when loading HTML resources. For example,

<script src="//foobar.com/js/script.js"></script>

The Location header, however, accepts an absolute URI. (See specification)

Upvotes: 0

Marc B
Marc B

Reputation: 360662

You have to use a proper absolute URL:

e.g. you're on "example.com", and want to redirect to "example.net":

header('Location: example.net:443');  // redirects to http://example.com/example.net:443
header('Location: http://example.net:443') // redirects to the url as written

Upvotes: 2

Related Questions