Apache URL 重写查询
谁能告诉我该怎么做?我很难过!
我需要一个修改后的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我现在无法测试它,但
应该获取 URL 中的 last“-id-”和“.html”之间的所有内容,并将其传递给index.php(将其更改为适合您的需求)通过 get 作为 id。
(注意.*后面的?,它使正则表达式非贪婪,以便匹配尽可能少的字符,确保它是最后一次出现的“-id-”)
I'm not able to test it right now, but
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-")