Using mod rewrite to change URL with username vari

2020-01-27 08:07发布

How do I change the following client-side URL

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

to a server-side URL of

domain.com/profile.php?user_id=100

with the username in a php variable?

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

How does Twitter manage their userpage URLs?

2条回答
手持菜刀,她持情操
2楼-- · 2020-01-27 08:42

Checkout the RewriteMap function.

查看更多
一纸荒年 Trace。
3楼-- · 2020-01-27 08:53

Try this rule:

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

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.

查看更多
登录 后发表回答