2011-09-21 53 views
0

我想知道是否有可能讓別人只能輸入鏈接:PHP內嵌URL重定向?

並讓它在人們訪問時真正進入真正的鏈接。

這是我的,但我不知道如何實現。

<?php 
if($_GET["k"] == "custom") header("Location: {$_POST["first"]}_{$_POST["last"]}"); 

$file = fopen("link.php", "r"); 

$data = fread($file, filesize("link.php")); 


$first = $_GET["n"]; 
$last = fixN($last); 
$data = str_replace("first", ucfirst(strtolower($first)), $data); 
$data = str_replace("last", ucfirst($last), $data); 


print $data; 

} 
?> 

在頁面上;

<BODY onLoad="first"> 

即使你做鏈接,它也不會只抓住最後一部分。這是我需要它重定向到。


<?php 
if (isset($_SERVER['REQUEST_URI'])) AND filter_var(trim($_SERVER['REQUEST_URI']),  FILTER_VALIDATE_URL)) { 

    header('Location: ' . $_SERVER['REQUEST_URI']); 

} 
?> 
<html> 
<head></head> 
<body> 
<a href="first">first</a> 
</body> 
</html> 

這是確切的鏈接http://LikeTreasure.com/google.com

我不知道什麼是錯。

即使您指定的文件類型http://LikeTreasure.com/file.html

它似乎總是發送整個URL。

回答

2

只要你是URL重寫是一個PHP文件...

if (isset($_SERVER['REQUEST_URI'])) AND filter_var(trim($_SERVER['REQUEST_URI']), FILTER_VALIDATE_URL)) { 

    header('Location: ' . $_SERVER['REQUEST_URI']); 

} 

這將如果REQUEST_URI環境變量設置的請求轉發(它不會在IIS),它看起來像一個有效的URL。