mod_rewrite关于修改url的问题

发布于 2024-08-21 15:57:00 字数 625 浏览 3 评论 0原文

我终于把 mod_rewrite 规则弄下来了,但想用它做更多的事情,但不知道如何做。这是我目前拥有的:

RewriteRule ^rider/(.*)/(.*)*$ /bar/standings/rider.php?lnum=$1&short=$2

这允许我这样做:

http://pca.localhost/rider/214142/sme 
instead of 
http://pca.localhost/bar/standings/rider.php?lnum=214142&short=sme

这一切都很好,但我想进一步改进它,这样它就会是:

http://pca.localhost/rider/fred/flinstone

但是,我需要传递 lnum 变量,因为它是唯一正确的id 密钥(即他们可能是数据库中名为 fred flinstone 的两个人)。短变量并不那么重要。我的目标是以某种方式仅传递名称而不显示 lnum 变量。有办法做到这一点吗?我可以在传递 lnum 变量时以某种方式隐藏它吗?或者,我需要做一些巧妙的 php/mysql 工作吗?

欢迎任何意见、意见或建议。

I've finally got the mod_rewrite rule down somewhat, but would like to do a bit more with it and am not sure how. Here's what I currently have:

RewriteRule ^rider/(.*)/(.*)*$ /bar/standings/rider.php?lnum=$1&short=$2

Which allows me to do this:

http://pca.localhost/rider/214142/sme 
instead of 
http://pca.localhost/bar/standings/rider.php?lnum=214142&short=sme

That works all fine and dandy, but I'd like to refine it more, so that it would be:

http://pca.localhost/rider/fred/flinstone

However, I need to pass the lnum variable because it's the only true id key (ie their could be two people in the db named fred flinstone). The short variable doesn't matter as much. My goal is to somehow pass just the name without showing the lnum variable. Is there a way to do this? Can I somehow hide the lnum variable when it's passed? Or, do I need to do some slick php/mysql work?

Any advice, comments or suggestions are welcomed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浪菊怪哟 2024-08-28 15:57:00

当客户首次访问您的网站时,您从他们那里获得的唯一密钥就是 URL。如果 URL 不能唯一标识要查看的页面,那么您必须显示某种消歧页面,或者必须放弃这个想法。

The only key you get from the client when they go to your website fresh is the URL. If the URL does not uniquely identify the page to view then you must either show some sort of disambiguation page or you must abandon the idea.

秋凉 2024-08-28 15:57:00

您可以尝试在注册时为用户生成一个唯一的 ID,并在整个过程中使用它。例如,对于 fred flinstone,

唯一 id = fred(如果没有 fred 已存在)
唯一 id = fred-flinstone(如果已经有 fred 存在)
unique id = fred-flinstone1 (如果已经有一个 fred flinstone 存在)

这种逻辑。

You can try generating a unique id for the user at the time of registration and use that throughout. For example for fred flinstone

unique id = fred (if there's no fred already present)
unique id = fred-flinstone (if there's already a fred present)
unique id = fred-flinstone1 (if there's already a fred flinstone present)

Some logic of this sort.

十年不长 2024-08-28 15:57:00

如果您首先必须从数据库获取 ID,为什么不在 cookie 中使用会话 ID?或者将会话 ID 作为 GET 或 POST 参数(即带有隐藏表单字段)。

无论如何,这样暴露用户ID并不是很安全。使用“随机”ID(例如会话 ID),并将其链接到用户 ID。

If you have to get the ID from the DB in the first place, why not using a session ID in a cookie? Or the session ID as GET or POST parameter (i.e. with a hidden form field).

Anyway, it is not very safe to expose the user ID like that. Use a "random" ID, like a session ID, and link it to the user ID.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文