2015-07-12 18 views
1

我怎麼能認識到這一點:通過進入鏈接實現用戶重定向用PHP

當用戶進入

mysite.com/index.php?g=123 

他將被重定向到mysite.com/123。

對於任何其他進入的值也是如此。例如:mysite.com/?g=456> mysite/456; mysite.com/?g=789> mysite/789;等 我都試過了,但我知道,這種方式是錯誤的:

<?php 
$g = checkValues($_REQUEST['g']);  
if($g)  
{  
header("Location: index.php/$g");  
} 
?> 

謝謝!

+0

'位置絕招 : index.php/###'但你要求'mysite.com/###' – 2015-07-12 23:50:23

+0

你能告訴我們你的'checkValues'函數嗎?請 – zilongqiu

回答

0

替換:

$g = checkValues($_REQUEST['g']); 

通過這個

$g = checkValues($_GET['g']); 
+0

$ _REQUEST包含$ _GET – 2015-07-12 23:53:50

+0

是的! :D它還包括$ _POST和$ _COOKIE。我認爲我們需要關注'checkValues'函數。 – zilongqiu

0

沒有測試這一點,但它應該做的把這個代碼在.htaccess文件

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteCond %{QUERY_STRING} g=(\d+) [NC] 
    RewriteRule^mysite.com/index.php/%1 [R=301,L] 
</IfModule>