使用mod-rewrite改变与用户名变量网址变量、用户名、网址、mod

2023-09-02 00:19:54 作者:凉城已无爱

如何更改下面的客户端网址

How do I change the following client-side URL

domain.com/profile/jung
domain.com/jung (preferable)

到服务器端的URL

to a server-side URL of

domain.com/profile.php?user_id=100

在一个PHP变量的用户名?

with the username in a php variable?

我知道我需要修改我的htaccess文件用的RewriteCond和重写规则,但它仍然不是很清楚,我...

I know I need to edit my htaccess file with a RewriteCond and RewriteRule but it's still not clear to me...

如何Twitter的管理他们的userpage网址?

How does Twitter manage their userpage URLs?

推荐答案

试试这个规则:

RewriteRule ^profile/([^/]+)$ profile.php?user_name=$1

这将改写请求 /型材/ foobar的 的到 /profile.php?user_name = foobar的 的。请注意,您只可以重写的用户名。然后,您的脚本将要查找的用户ID,如果有必要的。

This will rewrite requests of /profile/foobar to /profile.php?user_name=foobar. Note that you just can rewrite the user name. You script will then have to look up the user ID if necessary.