2011-12-29 33 views
0

我有一张地图用于在我的asp.net MVC应用程序中重写网址。我希望这条规则是以地图上查找值的存在为条件。如何在地图中使用rewritecond进行查找

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放在规则之上,但是如何查找?

回答

1

你试过:

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

这意味着如果${contentmap:$1}导致什么比一个空字符串(“”)越大,则与规则继续。

+0

谢谢,这个工作很好,给了我在IIS6扩展名的URL处理厌恶eurl.axd垃圾的想法。 – jason 2011-12-29 16:00:47

1

请尝试以下语法:

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