如何将 rewritecond 与地图中的查找结合使用

发布于 2024-12-23 09:33:13 字数 461 浏览 2 评论 0原文

我有一个地图,用于在我的 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 技术交流群。

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

发布评论

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

评论(2

韵柒 2024-12-30 09:33:13

您是否尝试过:

RewriteMap contentmap txt:content/maps/contentmap.txt [NC]
RewriteCond ${contentmap:$1}  >""  [NC]
RewriteRule home/([^/]*)$ /home/${contentmap:$1}/$1 [NC,L]

意思是如果 ${contentmap:$1} 结果大于空字符串 (""),则继续执行该规则。

Have you tried:

RewriteMap contentmap txt:content/maps/contentmap.txt [NC]
RewriteCond ${contentmap:$1}  >""  [NC]
RewriteRule home/([^/]*)$ /home/${contentmap:$1}/$1 [NC,L]

Meaning if ${contentmap:$1} results in anything larger than an empty string (""), then continue with the rule.

少女净妖师 2024-12-30 09:33:13

请尝试以下语法:

RewriteMap contentmap txt:content/maps/contentmap.txt [NC]
RewriteCond ${contentmap:$1|NOT_FOUND} !NOT_FOUND
RewriteRule home/([^/]*)$ /home/${contentmap:$1}/$1 [NC,L]

Please try the following syntax:

RewriteMap contentmap txt:content/maps/contentmap.txt [NC]
RewriteCond ${contentmap:$1|NOT_FOUND} !NOT_FOUND
RewriteRule home/([^/]*)$ /home/${contentmap:$1}/$1 [NC,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文