dpxnrx11199 2014-12-08 08:58
浏览 24

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

I have a domain www.domain.com and I have users who create profiles on it with a username. I have created a mechanism for them to access their public profile as www.domain.com/username using htaccess and some code in index.php file.

My .htaccess file looks like this:

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

An additional feature is that users can select a design (1st or 2nd design) for their profile. So I store the chosen design in database and redirect www.domain.com/username to www.domain.com/1/ or www.domain.com/2/ and load the users profile on that URL. The logic for that in PHP is

//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");
}

My problem is, how can I redirect in such a way that the URL is always www.domain.com/username and it loads the design in the background (logically) and displays it.

  • 写回答

1条回答 默认 最新

  • doushadu0901 2014-12-08 09:40
    关注

    It is not possible to hide information in a visible link. You can use a link like that:

    www.domain.com/username-1 redirect to -> www.domain.com/page.php?user=username&design=1

    For that kind of stuff, I use cookies...

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类