【问题标题】:How do rewrite the url in web.config file(iis 7.5)?如何重写 web.config 文件(iis 7.5)中的 url?
【发布时间】:2014-04-05 22:40:40
【问题描述】:

输入:域名.com/name

输出:domainname.com/page.aspx?n=name

我已经尝试了下面的代码。

<rewrite>
    <rules>
        <rule name="RedirectToWWW" stopProcessing="true">
            <match url=".*" ignoreCase="true" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^domain.com$" />
            </conditions>
            <action type="Redirect" url="page.aspx?n={R:0}" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>

它很酷。但是如果我只输入域名,那也是重写。如何避免这个问题?

【问题讨论】:

  • 您忘记添加代码了吗?

标签: c# asp.net .net url url-rewriting


【解决方案1】:
Oh my god ! finally got the solution.
<rewrite>
    <rules>
        <rule name="RedirectToWWW" stopProcessing="true">
            <match url="^(.+)$" />
        <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Redirect" url="page.aspx?n={R:0}"/>
        </rule>
    </rules>
</rewrite>

【讨论】:

    猜你喜欢
    • 2012-05-23
    • 2012-08-05
    • 1970-01-01
    • 2017-08-23
    • 2013-01-06
    • 2011-05-23
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    相关资源
    最近更新 更多