如果url是指定的,如何在PHP中创建重定向?

时间:2014-04-21 17:04:19

标签: php redirect

我想在一个文件中将localhost重定向到我的ip。如果我用我的IP不看重定向。 我已经编写了一些代码,但不做任何工作。

<?php
//if $actual_link = 'localhost/docs/headertest.php' {
//header( 'Location: http://MYIP/docs/headertest.php' );};
//echo $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]<br>";
//echo $_SERVER['SERVER_NAME'];
//echo "<br>";
//echo $_SERVER['SERVER_NAME']$_SERVER['REQUEST_URI'];
//if $actual_link =;
//if $_SERVER[REQUEST_URI] = "/docs/headertest.php" {
//header( 'Location: http://MYIP/docs/headertest.php' )};
//$url = "$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
//echo $url;
//if $url = "localhost/docs/headertest.php" {
//echo "asd";};
//header( 'Location: http://MYIP/docs/headertest.php' );};
$url = "http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]; 
$localhost = "http://localhost/docs/headertest.php";
if $url = ($localhost){
header( 'Location: http://MYIP/docs/headertest.php' );}
?>

感谢。

1 个答案:

答案 0 :(得分:0)

应该是:

$url = "http://".$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI]; 
$localhost = "http://localhost/docs/headertest.php";
if ($url == $localhost){
header( 'Location: http://MYIP/docs/headertest.php' );
}