个人资料页面网址如facebook profile -php

时间:2012-11-19 06:51:40

标签: php facebook .htaccess url-rewriting profile

有没有人可以帮我使用.htaccess文件自定义个人资料页面网址,如facebook个人资料和其他一些社交网站,如twitter。

对于登录我网站的所有用户,网址为www.mywebsite.com/view/profile。但我想将该网址更改为www.mywebsite.com/username。

.htaccess以外是否还有其他选项来自定义个人资料链接?

3 个答案:

答案 0 :(得分:3)

你可以看看:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*/([a-zA-Z0-9_-]+)|([a-zA-Z0-9_-]+))$ ./profile.php?username=$1 [L]

您可以复制上面的代码并将其粘贴到.htaccess文件中。 profile.php是你的php文件,它将读取用户名。 您可以通过创建profile.php并使用

来查看它
var_dump($_GET); die();

你会看到变量$ _GET ['username'] 从那里你可以查询你的SQL。 *注意sql注入并添加一些安全性。

答案 1 :(得分:0)

您的网站名称为example.com,并且您希望将所有要转到example.com/的传入网址重定向到example.com/profile.php

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^$ http://example.com/profile.php [L,R=301]

通过这种方式,如果请求包含http://example.com/accouthttp://example.com/settings之类的受限关键字等,您可以检入您的个人资料页面,然后重定向到您可以处理操作的页面,或者显示用户 比如http://example.com/rms

答案 2 :(得分:0)

您可以在

了解有关 .htaccess 的更多信息

http://httpd.apache.org/docs/2.2/howto/htaccess.html