2014-02-20 110 views
1

我正在嘗試爲具有多個域的站點創建URL重寫。例如,其中一個域是mydomain.com,如果用戶將www.mydomain.com放入其瀏覽器中,並且未指定頁面,我想重寫該URL以致電www.mydomain.com/landingpage.aspx?cat=1 & sol = 4。如何爲僅限域的請求創建URL重寫規則?

如果用戶調用任何其他內容,如www.mydomain.com/somepage.aspx,則應忽略此規則。

我已經在服務器2008 R2機器上安裝了URL Rewrite 2.0,並且已將此規則添加到web.config中。

<rewrite> 
<rules> 
    <rule name="mydomain.com" stopProcessing="true"> 
     <match url=".*" /> 
     <conditions> 
      <add input="{HTTP_HOST}" pattern="^(www.)?mydomain.com" /> 
      <add input="{PATH_INFO}" pattern="^$" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="\landingpage.aspx?cat=1&sol=4" /> 
    </rule> 
</rules> 
</rewrite> 

我使用的是{} PATH_INFO^$的,這樣,如果不只是一個呼籲領域的任何其他發生這應該忽略它,我認爲。但它不起作用。

我在網站上使用.NET 4.0。

有人能告訴我我做錯了嗎?

回答

0

您正在尋找以下規則:

這將檢查網址是否爲空,即沒有任何頁面使用匹配的URL =^$指定 - 空字符串,然後重定向到特定頁面。

<rule name="Redirect to specific page" enabled="true" stopProcessing="true"> 
    <match url="^$" /> 
    <conditions> 
     <add input="{HTTP_HOST}" pattern="^(www.)?mydomain.com$" /> 
    </conditions> 
    <action type="Redirect" url="http://{HTTP_HOST}/landingpage.aspx?cat=1&sol=4" /> 
</rule>