就像带有 rewritecond 的 twitter url 一样?

发布于 2024-08-24 18:32:44 字数 430 浏览 1 评论 0原文

我想要一个简单的帮助。我有一个像这样的 URL:/profile.php?id=&name=

我的 .htaccess 文件是这样的:

RewriteRule ^profile/(.*)/(.*) profile.php?id=$1&name=$2

所以我有一个像这样的结束 URL:/profile//

我可以制作/。但是我怎样才能获得像/这样的URL呢?

我可以使用 RewriteCond 来创建条件吗? 我仍然没有很多 .htaccess。

I would like a simple help. I have a URL like this: /profile.php?id=<id>&name=<name>.

My .htaccess file like this:

RewriteRule ^profile/(.*)/(.*) profile.php?id=$1&name=$2

So I have a end URL like this: /profile/<id>/<name>.

I can make /<id>. But how can I get a URL like /<name>?

I can use the RewriteCond to make a conditional?
I still don't a lot of .htaccess.

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

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

发布评论

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

评论(1

手心的海 2024-08-31 18:32:44

如果名称和 ID 的值具有不同的模式,您可以在规则中使用这些模式,例如:

# numerical IDs
RewriteRule ^[1-9]\d*$ profile.php?id=$0

# names
RewriteRule ^[a-z]+$ profile.php?name=$0

If the names and IDs have a different pattern in their values, you could use these patterns in your rules, for example:

# numerical IDs
RewriteRule ^[1-9]\d*$ profile.php?id=$0

# names
RewriteRule ^[a-z]+$ profile.php?name=$0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文