如何将 rewritecond 与地图中的查找结合使用
我有一个地图,用于在我的 asp.net MVC 应用程序中重写 url。我希望此规则以地图中存在查找值为条件。
RewriteMap contentmap txt:content/maps/contentmap.txt [NC]
RewriteRule home/([^/]*)$ /home/${contentmap:$1}/$1 [NC,L]
这需要 url home/some-content-id
并将其重写为 home/someaction/some-content-id
我遇到的问题有时是模式 home/some-other-content-id
可能在内容映射中不匹配。没关系,但规则仍然尝试(或看起来如此)重写,如果不重写会更好。
我最初的想法是在规则之上放置一个 rewritecond,但是如何进行查找呢?
I have a map that I use to rewrite urls in my asp.net MVC application. I would like this rule to be conditional on the presence of the lookup value in the map.
RewriteMap contentmap txt:content/maps/contentmap.txt [NC]
RewriteRule home/([^/]*)$ /home/${contentmap:$1}/$1 [NC,L]
this takes the url home/some-content-id
and rewrites it as home/someaction/some-content-id
The problem I am running into is sometimes the pattern home/some-other-content-id
may not match in the content map. Thats ok but the rule still attempts (or seemingly so) to rewrite when it would be better if it didn't.
My initial thought is to put a rewritecond above the rule, but how do you do the lookup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过:
意思是如果
${contentmap:$1}
结果大于空字符串 (""),则继续执行该规则。Have you tried:
Meaning if
${contentmap:$1}
results in anything larger than an empty string (""), then continue with the rule.请尝试以下语法:
Please try the following syntax: