【问题标题】:How can I create a URL rewrite rule for a domain-only request?如何为仅限域的请求创建 URL 重写规则?
【发布时间】:2014-03-22 05:09:56
【问题描述】:

我正在尝试为具有多个域的站点创建 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。

谁能告诉我我做错了什么?

【问题讨论】:

    标签: asp.net .net url url-rewriting url-rewrite-module


    【解决方案1】:

    您正在寻找以下规则:

    这将检查 URL 是否为空,即没有使用匹配 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-14
      • 1970-01-01
      相关资源
      最近更新 更多