2013-04-02 34 views
0

我可以重定向,並作出單一友好的URL:具有相同的圖案友好的URL

<rule name="RedirectUserFriendlyURL1" stopProcessing="true"> 
    <match url="^Product/Tour\.aspx$" /> 
     <conditions> 
      <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> 
     </conditions> 
     <action type="Redirect" url="Product/Tour" appendQueryString="false" /> 
</rule> 

<rule name="RewriteUserFriendlyURL2" stopProcessing="true"> 
    <match url="^Product/Tour$" /> 
     <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     </conditions> 
    <action type="Rewrite" url="Product/Tour.aspx" /> 
</rule> 

但是,舉例來說,如果我有:

http://www.domain.com/Product/Features.aspx 
http://www.domain.com/Product/Download.aspx 
http://www.domain.com/Product/FAQ.aspx 

我可以寫一條規則爲所有這些鏈接建立友好的URL以便接收?

http://www.domain.com/Product/Features 
http://www.domain.com/Product/Download 
http://www.domain.com/Product/FAQ 

有一些鏈接很容易,但有很多規則很難維護。

回答

0

您可以使用正則表達式模式和back reference做到這一點:

<rule name="RedirectUserFriendlyURL1" stopProcessing="true"> 
    <match url="^Product/([A-z0-9]+)\.aspx$" /> 
     <conditions> 
      <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> 
     </conditions> 
     <action type="Redirect" url="Product/{R:1}" appendQueryString="false" /> 
</rule> 

<rule name="RewriteUserFriendlyURL2" stopProcessing="true"> 
    <match url="^Product/([A-z0-9]+)$" /> 
     <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     </conditions> 
    <action type="Rewrite" url="Product/{R:1}.aspx" /> 
</rule> 

如果你有很多的url重寫,你應該閱讀有關Rewrite Maps的文件也是如此。