重定向至另一个非标准端口(IP:端口)的站点


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

如何重定向到另一个在Php或Html上没有标准端口(IP:Port)的站点?

在php上,我尝试使用header('Location: IP:PORT' );

有什么技巧可以解决这个问题吗?

您必须使用正确的绝对 URL:

例如,您在"example.com"上,并且想要重定向到"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

你应该在地址前面添加http:////,告诉PHP它是一个绝对的URL。

例如,如果要重定向到端口 8888 上的123.123.123.123,则可以执行以下操作:

<?php
header('Location: http://123.123.123.123:8888');
?>

注意:

通常建议您使用 //,而不是显式指定http://

在加载 HTML 资源时,使用 // 是有意义的(仅?例如

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

但是,Location标头接受绝对 URI。(见规格)