2015-07-12 20 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>