2015-10-13 108 views
0

一個特定的頁面我要添加打開下面的頁面 http://test.com/Collection.aspx?title=Women追加查詢字符串在重寫規則的Web.config

http://tests.com/Women

http://tests.com/Collection.aspx?title=Women

as

http://test.com/pathann

我試圖使用下面的重寫規則,但這些工作的所有頁面,我只是想實現這個特定的部分。

<rule name="RedirectUserFriendlsssyURL1" stopProcessing="true"> 
     <match url="^Collection\.aspx$" /> 
     <conditions> 
     <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> 
     <add input="{QUERY_STRING}" pattern="^title=([^=&amp;]+)$" /> 
     </conditions> 
     <action type="Redirect" url="{C:1}" appendQueryString="false" /> 
    </rule> 
     <rule name="RewriteUserFriendlyURL1" stopProcessing="true"> 
     <match url="^([^/]+)/?$" /> 
     <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="Collection.aspx?title={R:1}" /> 
    </rule> 

請幫我,我該如何做這些特定頁面只。其實如果我申請所有頁面,它會阻止其他一些功能的工作。

回答

1

我會在你的情況做的是隻重定向的部分留到URL重寫模塊:通過在Global.asax的路由

<rule name="RedirectUserFriendlsssyURL1" stopProcessing="true"> 
    <match url="^Collection\.aspx$" /> 
    <conditions> 
    <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> 
    <add input="{QUERY_STRING}" pattern="^title=([^=&amp;]+)$" /> 
    </conditions> 
    <action type="Redirect" url="{C:1}" appendQueryString="false" /> 
</rule> 

和處理的其餘部分:

void Application_Start(object sender, EventArgs e) 
{ 
    RegisterRoutes(RouteTable.Routes); 
} 

void RegisterRoutes(RouteCollection routes) 
{ 
    routes.MapPageRoute("CollectionRoute", 
     "{title}", 
     "~/Collection.aspx", false, 
     new RouteValueDictionary(), 
     //Here you can define the regex pattern to match the title phrases 
     new RouteValueDictionary { 
      { "title", "(women)|(pathann)" } 
     }); 
} 

但是,當然,如果您仍然傾向於保留通過url重寫模塊處理的所有內容,您可以像這樣定義規則:

<rule name="RewriteUserFriendlyURL1" stopProcessing="true"> 
     <match url="(women)|(pathann)" /> 
     <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="Collection.aspx?title={R:1}" /> 
</rule>