代码之家  ›  专栏  ›  技术社区  ›  citronas

为什么URL重写2.0不起作用?

  •  0
  • citronas  · 技术社区  · 14 年前

    我正在本地IIS 7.5上运行一个.NET Framework 4 Web应用程序项目,安装了url rewrite 2.0模块。

    我的应用程序包含一个名为sitemap.aspx的页面。我希望能够将/sitemap/映射到sitemap.aspx

    这是迄今为止我的代码,但不起作用。在调用/sitemap时,我将得到一个404 Not Found错误屏幕。缺少什么?

       <rewrite>
            <rules>
                <rule name="LowerCaseRule1" enabled="true" stopProcessing="true">
                    <match url="[A-Z]" ignoreCase="false" />
                    <conditions>
                        <add input="{URL}" matchType="Pattern" pattern="^.+\.((axd)|(js)|(xaml))$" ignoreCase="true" negate="true" />
                    </conditions>
                    <action type="Redirect" url="{ToLower:{URL}}" redirectType="Permanent" />
    
                </rule>
                <rule name="RemoveTrailingSlashRule1" stopProcessing="true" enabled="true">
                    <match url="(.*)/$" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    </conditions>
                    <action type="Redirect" url="{R:1}" />
                </rule>
            </rules>
            <rewriteMaps>
                <rewriteMap name="test">
                    <add key="/sitemap" value="sitemap.aspx"/>
                </rewriteMap>
            </rewriteMaps>
        </rewrite>
    
    1 回复  |  直到 14 年前
        1
  •  0
  •   citronas    14 年前

    我错过了一个条目:

    添加

            <rule name="Rewrite rule1 for test">
                <match url=".*" />
                <conditions>
                    <add input="{test:{REQUEST_URI}}" pattern="(.+)" />
                </conditions>
                <action type="Rewrite" url="{C:1}" appendQueryString="false" />
            </rule>
    

    一切都很好