簡體   English   中英

如何為僅域請求創建URL重寫規則?

[英]How can I create a URL rewrite rule for a domain-only request?

我正在嘗試為具有多個域的站點創建URL重寫。 例如,其中一個域是mydomain.com,如果用戶將www.mydomain.com放在其瀏覽器中但未指定頁面,則我要重寫URL來調用www.mydomain.com/landingpage.aspx?cat=1&sol = 4。

如果用戶調用了其他任何內容,例如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。

有人可以告訴我我在做什么錯嗎?

您正在尋找以下規則:

這將檢查URL是否為空,即使用match 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM