我不能肯定我完全瞭解你的需求,但這裏的東西是至少接近。它刪除第一個文件夾和文件擴展名(所以examplesite.com/folder/about.cshtml
變成examplesite.com/about
和examplesite.com/folder/help/about.cshtml
變成examplesite.com/help/about
)。如果你想剝離所有文件夾,然後刪除?
。
<rule name="Remove Directory and Extension">
<match url="^(.*?)/(.*)\.cshtml$" />
<action type="Rewrite" url="{R:2}" />
</rule>
更新:
好吧,我想你想要的東西是那麼兩個規則的組合:
<rules>
<rule name="Redirect requests to friendly URLs">
<match url="^(.*?)/(.*)\.cshtml$" />
<action type="Redirect" url="{R:2}" />
</rule>
<rule name="Rewrite friendly URLs to phsyical paths">
<match url="^(.*)$" />
<action type="Rewrite" url="folder/{R:0}.cshtml" />
</rule>
</rules>
的第一條規則將確保所有的請求都以友好的URL。第二個採用友好的URL並將其重寫爲物理路徑,物理路徑爲folder/[FRIENDLY_PATH].cshtml
。
IIRC with Razor你可以放棄'.cshtml' - 無論如何 - http://www.asp.net/web-pages/tutorials/working-with-pages/creating-readable-urls-in-aspnet-web- pages-sites – Lloyd 2013-02-21 22:10:07