2017-07-16 45 views
0

我有兩個網址:http://...../m?PageView=View1&Language=English&AName=AAA和另一個http://...../m?PageView=View2TName=T1&AName=XYZ。這兩個網址都是用於單獨的部分/功能。但是因爲參數的數量和模式是相同的,所以一個url工作而另一個不工作。類似網址的IIS管理器url規則

我想寫兩個類似url的url重定向和重寫規則。我寫了第一條規則如下。

<rule name="RedirectUserFriendlyURL12" stopProcessing="true"> 
     <match url="^m/$" /> 
     <conditions> 
     <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> 
     <add input="{QUERY_STRING}" pattern="^View=([^=&amp;]+)&amp;Language=([^=&amp;]+)&amp;AName=([^=&amp;]+)$" /> 
     </conditions> 
     <action type="Redirect" url="m/{C:1}/{C:2}/{C:3}" appendQueryString="false" /> 
    </rule> 
    <rule name="RewriteUserFriendlyURL12" stopProcessing="true"> 
     <match url="^m/([^/]+)/([^/]+)/([^/]+)/?$" /> 
     <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="m?View={R:1}&amp;Language={R:2}&amp;AName={R:3}" /> 
</rule> 

和另一個url具有相同數量的參數,但名稱不同,如下所示。這是第二條規則。

<rule name="RedirectUserFriendlyURL12" stopProcessing="true"> 
     <match url="^m/$" /> 
     <conditions> 
     <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> 
     <add input="{QUERY_STRING}" pattern="^View=([^=&amp;]+)&amp;TName=([^=&amp;]+)&amp;AName=([^=&amp;]+)$" /> 
     </conditions> 
     <action type="Redirect" url="m/{C:1}/{C:2}/{C:3}" appendQueryString="false" /> 
    </rule> 
    <rule name="RewriteUserFriendlyURL12" stopProcessing="true"> 
     <match url="^m/([^/]+)/([^/]+)/([^/]+)/?$" /> 
     <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="m?View={R:1}&amp;TName={R:2}&amp;AName={R:3}" /> 
</rule> 

當我在web.config中有以上兩條規則時,一個url可以正常工作,即重寫和重寫但是另一個不起作用。

如何區分這兩個規則,以便它適用於這兩個網址。

+0

你能提供你想要的樣品或重定向嗎?這將有助於我理解你的規則,以及如何正確編寫 –

+0

修改過的問題在頂部。現在看看你是否可以幫忙.. – ghetal

+0

你的重定向不工作?或重寫不起作用?你的第二個'RewriteUserFriendlyURL12'將不起作用,因爲它具有與第一次重寫相同的'conditions'和'match url'。所有的請求將被重寫'RewriteUserFriendlyURL12' –

回答

0

我解決了我的問題。我只保留了一條規則,第一條。

但是在我的控制器代碼中,實際上我必須相應地映射參數。意思不是TName參數值我必須訪問,我也只能訪問View-2的語言參數,因爲當應用規則時,TName的值將越過語言參數。

我可以使用兩條規則,但我必須更改重定向目標URL。像重定向

^View=([^=&]+)&TName=([^=&]+)&AName=([^=&]+)$ to m/{C:1}/tname/{C:2}/{C:3} 

然後從

^m/([^/]+)/tname/([^/]+)/([^/]+)/?$ to m?View={R:1}&TName={R:2}&AName={R:3}. 

改寫回去,但我不希望有這樣的事情上面。