mod_rewrite 忽略最后一个目录(如果它是第三个目录)

发布于 2024-10-07 18:39:42 字数 280 浏览 1 评论 0原文

如果 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 技术交流群。

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

发布评论

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

评论(1

倥絔 2024-10-14 18:39:42

像这样的东西应该可以满足您的要求:

RewriteRule ^([^/]*)/([^/]+)$ /$1

如果您想在参数或其他内容中保留最后一个目录名称,您也可以在重写中使用 $2 。例如:(

RewriteRule ^([^/]*)/([^/]+)$ /$1?foo=$2

旁白:我注意到 3 个目录实际上意味着 2 个目录。第一件事是主机名,而不是目录。)

Something like this should do what you want:

RewriteRule ^([^/]*)/([^/]+)$ /$1

You can also use $2 in the rewrite if you want to preserve the last directory name in a parameter or something. eg:

RewriteRule ^([^/]*)/([^/]+)$ /$1?foo=$2

(Aside: I notice that by 3 directories you actually mean 2. That first thing is the hostname, not a directory.)

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