2011-12-29 17 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] 
相關問題