mod_rewrite 忽略最后一个目录(如果它是第三个目录)
如果 url 包含三个目录,您将如何删除最后一个目录
For example this url
www.mysite.com/dir/removeMe
would map to
www.mysite.com/dir
However
www.mysite.com/dir
would still map to
www.mysite.com/dir
我正在尝试使用更漂亮的链接而不是 www.mysite.com/dir/?name=removeMe
谢谢。
How would you remove the last directory if the url contains three directories
For example this url
www.mysite.com/dir/removeMe
would map to
www.mysite.com/dir
However
www.mysite.com/dir
would still map to
www.mysite.com/dir
I am trying to use prettier links instead of www.mysite.com/dir/?name=removeMe
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样的东西应该可以满足您的要求:
如果您想在参数或其他内容中保留最后一个目录名称,您也可以在重写中使用
$2
。例如:(旁白:我注意到 3 个目录实际上意味着 2 个目录。第一件事是主机名,而不是目录。)
Something like this should do what you want:
You can also use
$2
in the rewrite if you want to preserve the last directory name in a parameter or something. eg:(Aside: I notice that by 3 directories you actually mean 2. That first thing is the hostname, not a directory.)