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

重写规则以将位置映射到静态文件

  •  2
  • madcapnmckay  · 技术社区  · 15 年前

    我想做的是重写locations文件夹中一堆静态页面的URL,这样

    伦敦

    映射到物理文件(如果它存在于locations文件夹中),例如。

    /地点/伦敦.aspx

    是否可以使用URL重写。我不能让规则生效。

    <rule name="Rewrite Locations">
        <match url="^([_0-9a-z-]+)/*" />
            <conditions>
                <add input="/locations/{REQUEST_FILENAME}.aspx" matchType="IsFile" />
            </conditions>
            <action type="Rewrite" url="/locations/{R:1}.aspx" />
    </rule>
    

    多谢,

    伊恩

    1 回复  |  直到 15 年前
        1
  •  0
  •   Carlos Aguilar Mares    15 年前

    要使isfile工作,您必须传递正确的物理路径,而不是虚拟路径,您可以执行以下操作:

    <rule name="Locations" stopProcessing="true">
        <match url="^([_0-9a-z-]+)/*" />
        <conditions>
            <add input="{APPL_PHYSICAL_PATH}locations\{R:1}.aspx" matchType="IsFile" />
        </conditions>
        <action type="Rewrite" url="/locations/{R:1}.aspx" />
    </rule>
    
    推荐文章