-3
我想開發一個URL路由器,當一個特定的URL來的時候,我將我的程序重定向到一個特定的URL。它甚至有可能嗎? 在此先感謝...PHP當一個特定的URL來時,如何重定向到另一個頁面
我想開發一個URL路由器,當一個特定的URL來的時候,我將我的程序重定向到一個特定的URL。它甚至有可能嗎? 在此先感謝...PHP當一個特定的URL來時,如何重定向到另一個頁面
您可以發送一個HTTP報頭重定向到另一個頁面:
header("Location: foo.php");
...或一個完整的URL:
header("Location: http://www.google.co.uk/");
注意,你應該在任何其他輸出(即回聲)之前發送標頭。
,如果你想測試一個「特殊」的網址,你需要先構建它:
$ssl = "";
if ((isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]=="on") || (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"]=="443"))
{ $ssl = "s"; }
$serverport = ($_SERVER["SERVER_PORT"]!="80"?":".$_SERVER["SERVER_PORT"]:"");
$theurl = "http".$ssl."://".$_SERVER["SERVER_NAME"].$serverport.$_SERVER["REQUEST_URI"];
然後,你可以測試它反對另一個URL(或它們的陣列):
if ($theurl != $myurl) {
header("Location: index.php");
}
對網址的數組:
if (in_array($theurl,$myurls)) {
header("Location: index.php");
}
ù想重定向到不同的網址每次?需要更多的解釋。 – Katti