htaccess将用户重定向到他的个人资料

时间:2014-12-08 08:58:39

标签: php apache .htaccess mod-rewrite redirect

我有一个域www.domain.com,我有用户使用用户名在其上创建配置文件。我创建了一种机制,让他们使用htaccess和index.php文件中的一些代码以www.domain.com/username的形式访问他们的公开个人资料。

我的.htaccess文件如下所示:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L,QSA]

另一个功能是用户可以为其个人资料选择设计(第一或第二个设计)。因此,我将所选设计存储在数据库中,并将www.domain.com/username重定向到www.domain.com/1/www.domain.com/2/,然后在该网址上加载用户个人资料。 PHP 中的逻辑是

//Load profile of user
$requestURI = $_SERVER['REQUEST_URI'];
$parameterArray = explode('/', $requestURI);
$username = $parameterArray[1];

if($username != "")
{
    //Get chosen design from database and store it in a variable
    $chosenDesign = *Selected design value*;
    header("Location: $chosenDesign/");
}
else
{
    //Username not found, hence redirect to error page
    header("Location: 404.html");
}

我的问题是,如何重定向以使URL始终为www.domain.com/username并在后台加载设计(逻辑上)并显示它。

1 个答案:

答案 0 :(得分:0)

无法隐藏可见链接中的信息。 您可以使用以下链接:

www.domain.com/username-1重定向到 - > www.domain.com/page.php?user=username&design=1

对于那种东西,我使用cookies ......

相关问题