Apache URL 重写查询

发布于 2024-08-31 12:18:44 字数 234 浏览 2 评论 0原文

谁能告诉我该怎么做?我很难过!

我需要一个修改后的 URL,格式为

this55-is-a-test-id-23.html

但我需要 23 作为 GET。我不能依赖搜索“id”,因为这可能会出现在 URL 的其他位置。有没有什么方法可以搜索 id 的最后一次出现并将其作为 get 使用 .htaccess 中的 Apache RewriteRule 传递?

非常感谢

蚂蚁

Can anyone tell me how to do this? i'm stumped!

I need a modified URL in this format

this55-is-a-test-id-23.html

But I need the 23 as a GET. I can't rely on searching for 'id' as this may occur elsewhere in the URL. Is there any way of searching for the last occurrence of id and passing that as a get using an Apache RewriteRule in .htaccess??

Many thanks

Ant

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

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

发布评论

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

评论(1

梦在夏天 2024-09-07 12:18:44

我现在无法测试它,但

RewriteRule ^.*-id-(.*?)\.html$ index.php?id=$1 [L]

应该获取 URL 中的 last“-id-”和“.html”之间的所有内容,并将其传递给index.php(将其更改为适合您的需求)通过 get 作为 id。

(注意.*后面的?,它使正则表达式非贪婪,以便匹配尽可能少的字符,确保它是最后一次出现的“-id-”)

I'm not able to test it right now, but

RewriteRule ^.*-id-(.*?)\.html$ index.php?id=$1 [L]

should get everything between the last "-id-" in the URL and ".html" and pass it to index.php (change it to fit your needs) as id via get.

(Notice the ? after .*, it makes the regular expression non-greedy, so that it matches as fewer characters as possible, making sure it's the last occurrence of "-id-")

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