使用 mod rewrite 更改带有用户名变量的 URL [英] Using mod rewrite to change URL with username variable

查看:18
本文介绍了使用 mod rewrite 更改带有用户名变量的 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改以下客户端 URL

How do I change the following client-side URL

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

domain.com/profile.php?user_id=100

在 php 变量中使用用户名?

with the username in a php variable?

我知道我需要使用 RewriteCond 和 RewriteRule 编辑我的 htaccess 文件,但我仍然不清楚...

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

Twitter 如何管理他们的用户页面 URL?

How does Twitter manage their userpage URLs?

推荐答案

试试这个规则:

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

这会将 /profile/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.

这篇关于使用 mod rewrite 更改带有用户名变量的 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆