Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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_Social Networking - Fatal编程技术网

Php 重写链接到页面的URL

Php 重写链接到页面的URL,php,.htaccess,social-networking,Php,.htaccess,Social Networking,几乎每个人都去了Facebook。在Facebook上,他们有一个类似www.Facebook.com/username 但是,在一个用户结构如下的站点上:site.com/profile.php?user=username如何将链接重写为Facebook(即:site.com/username),这样,如果在浏览器中转到site.com/username,它实际上将链接到site.com/profile.php?user=username,而不只是在页面上时看起来它正在重写URL?这应该可以:

几乎每个人都去了Facebook。在Facebook上,他们有一个类似
www.Facebook.com/username
但是,在一个用户结构如下的站点上:
site.com/profile.php?user=username
如何将链接重写为Facebook(即:
site.com/username
),这样,如果在浏览器中转到
site.com/username
,它实际上将链接到
site.com/profile.php?user=username
,而不只是在页面上时看起来它正在重写URL?

这应该可以:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /profile\.php\?username=(.*)\ HTTP
RewriteRule ^ /%2\? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /profile.php?user=$1 [L]