Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
仅针对特定值在php中重写Url_Php_.htaccess - Fatal编程技术网

仅针对特定值在php中重写Url

仅针对特定值在php中重写Url,php,.htaccess,Php,.htaccess,我有一个链接 http://sonibazar.in/profile.php?id=1 我想把它重定向到 http://sonibazar.in/username http://sonibazar.in/anotherusername 同上 我有另一个不同的链接 http://sonibazar.in/profile.php?id=2 要将其重定向到 http://sonibazar.in/username http://sonibazar.in/anotherusername 所有

我有一个链接

http://sonibazar.in/profile.php?id=1
我想把它重定向到

http://sonibazar.in/username
http://sonibazar.in/anotherusername
同上 我有另一个不同的链接

http://sonibazar.in/profile.php?id=2
要将其重定向到

http://sonibazar.in/username
http://sonibazar.in/anotherusername
所有这些都在profile.php中,但我希望使用不同的地址和不同的值来使用它们

这有点像Facebook用户名分配。。。我想为我的网站中的用户创建用户名。因此,他们可以直接登录到他们的个人资料中(无需登录).

URL

profile.php

$user = ''; // From database

if($_GET['id'] == $user){
    echo "hi ".$user->name.", You're Rock!";
}
.htaccess

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/?$ profile.php?id=$1

用户是否存储在数据库中?是的,用户存储在数据库中,但不是用户名…我们可以强制重定向
http://domain.com/profile.php?id=1
http://domain.com/kristories
当用户打开
http://domain.com/profile.php?id=1
是。你可以通过
.htaccess
PHP
来完成。我知道怎么做?我对.htaccess不太了解,你能举个例子吗?