【问题标题】:match url regexp for subfolder on IIS 7 with web.config将 IIS 7 上子文件夹的 url 正则表达式与 web.config 匹配
【发布时间】:2012-11-03 23:33:04
【问题描述】:

我在我的 ISS 服务器上使用 get simple cms(实际上必须使用 ISS),并且有一个插件可以使用 web.config 在 ISS 上启用重写。

web.config 来源:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <rewrite>
        <rules>
            <rule name="GetSimple Fancy URLs" stopProcessing="true">
                <match url="^([^/]+)/?$" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="?id={R:1}" />
            </rule>
     </rules>
    </rewrite>
</system.webServer>
</configuration>

但我的 CMS 位于主文件夹 / 和子文件夹 /en 上,例如:

http://domainname.com/(主cms) http://domainname.com/en/(子文件夹上的另一个 cms)

使用上面的web.config,主 cms 工作成功,但子文件夹上的 cms 不工作(像以前一样给出 404)

如何将子文件夹规则实施到web.config file?所以 2 cms 工作成功。

我尝试将相同的 web.config 文件放在子文件夹 (/en) 下,但没有成功。

非常感谢,

【问题讨论】:

    标签: iis-7 url-rewriting web-config


    【解决方案1】:

    首先,您的正则表达式只会匹配实际上位于您网站根目录中的 URL,例如domain.com/pagedomain.com/anotherpage。它不会匹配像domain.com/subdir/page 这样的子目录。但这可能正是你想要的,我不知道。

    要使其也适用于/en,请将规则更改为:

    <rule name="GetSimple Fancy URLs" stopProcessing="true">
        <match url="^(en/)?([^/]+)/?$" />
        <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="{R:1}?id={R:2}" />
    </rule>
    

    如果您想要一个适用于任何两个字符语言代码的更通用的解决方案,请使用:

    <rule name="GetSimple Fancy URLs" stopProcessing="true">
        <match url="^([a-z]{2}/)?([^/]+)/?$" />
        <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="{R:1}?id={R:2}" />
    </rule>
    

    这应该只是在您根目录的web.config 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-07
      • 2015-05-30
      • 1970-01-01
      • 1970-01-01
      • 2013-08-05
      相关资源
      最近更新 更多