繁体   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