mod_rewrite - 需要有关友好 URL 的帮助

发布于 2024-08-16 03:53:42 字数 229 浏览 8 评论 0原文

你会如何mod_rewrite从directory.php转到url

?id=4 到 directory/category/city/name/4/

我在黑暗中尝试了一下,

RewriteRule ^directory/*/*/*/([^/\.]+)/?$ directory.php?&id=$4

但显然没有工作。非常感谢任何帮助

How would you mod_rewrite a url to go from

directory.php?id=4
to
directory/category/city/name/4/

I took a stab in the dark with

RewriteRule ^directory/*/*/*/([^/\.]+)/?$ directory.php?&id=$4

But not working obviously. Any help is greatly appreciated

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

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

发布评论

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

评论(1

十级心震 2024-08-23 03:53:42

怎么样:

RewriteRule ^directory\.php/.*/.*/.*/(.*)/$ directory.php?id=$1

括号执行捕获,并且由于您只执行一次捕获,因此可以在目标中使用“$1”。

编辑:我假设您希望不带查询字符串的 URL 重定向到带查询字符串的 URL(您的问题不是 100% 清楚,听起来好像是相反的情况)

How about:

RewriteRule ^directory\.php/.*/.*/.*/(.*)/$ directory.php?id=$1

The parentheses do the capture, and since you are only doing one capture, then the can use '$1' in the target.

Edit: I'm assuming that you want the URL without the query string to redirect to the one with the query string (not 100% clear in your question, sounds like it is the other way around)

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