.htaccess 有没有更有效的方法来做到这一点?
我有这种格式的 URL
site.com/brochure/12/subcat/subcat/maincat
对于我的应用程序来说,字符串中唯一重要的部分是小册子后面的数字 有时可能会有许多 subcat
错误目录,因此我必须使用许多类似的规则才能使其正常工作
RewriteRule ^brochure/([^/]+)/([^/] +)/([^/]+)/?$小册子.php?cat_path=$1
RewriteRule ^小册子/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$小册子.php?cat_path=$1
RewriteRule ^小册子/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ 小册子.php?cat_path=$1
等等 - 有时最多有五个不同的规则来允许不同的目录结构。
我猜这可以通过一条规则来完成,任何人都可以分享他们的想法吗?
谢谢
I have URLs in this format
site.com/brochure/12/subcat/subcat/maincat
The only important part of the string to my application is the number directly after brochure
There can sometimes be many subcat
false directories so I've had to use many rules like these to make it work
RewriteRule ^brochure/([^/]+)/([^/]+)/([^/]+)/?$ brochure.php?cat_path=$1
RewriteRule ^brochure/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ brochure.php?cat_path=$1
RewriteRule ^brochure/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ brochure.php?cat_path=$1
etc etc - sometimes up to five different rules to allow for the different directory structures.
I'm guessing this can be done in a single rule, anyone kind enough to share their ideas?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
既然您不关心初始
([^/]+)
之后字符串的任何部分,为什么不直接使用类似的内容:这将匹配并分组您的
12
,然后安静地匹配并丢弃字符串的其余部分 (.*$
)。Since you don't care about any part of the string after your initial
([^/]+)
, why not just use something like:This will match and group your
12
, then quietly match and discard the remainder of the string (.*$
).