如何从 IIS 上的 url 地址隐藏子文件夹(RewriteRule)?

How to hide subfolder from url addresses on IIS (RewriteRule)?

我正在尝试从 URL 中删除 /frontend/web/backend/web windows 服务器使用 IISweb.config 作为 .htaccess[ 的替代方案=13=]

原始 .htaccess 文件,我需要将其转换为 web.config:

Options FollowSymlinks
RewriteEngine on
RewriteRule ^admin(.+)?$ backend/web/ [L,PT]
RewriteRule ^(.*)$ frontend/web/ [L]

我只能像这样使用 web.config 删除 /frontend/web:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <clear />
                <rule name="RewriteRequestsToPublic" stopProcessing="true">
                    <match url="^(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="frontend/web/index.php/{R:0}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

这造成了一个问题,现在所有图像、css 和 JS 文件都不再加载,它们都给出 404

此外,当使用 /backend/web 时,这并不能解决我的问题,因为这是假设要重写任何包含 admin 的 url 到它了。

我能够做到这一点的唯一方法是添加所有可能的规则,最后添加通用规则,因为最重要的规则具有更高的优先级

像这样:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="AdminThemes" stopProcessing="true">
                    <match url="themes/admin(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="backend/web/{R:0}" />
                </rule>
                <rule name="AdminAssets" stopProcessing="true">
                    <match url="admin/assets/(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="backend/web/assets/{R:1}" />
                </rule>
                <rule name="AdminJs" stopProcessing="true">
                    <match url="admin/js/(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="backend/web/js/{R:1}" />
                </rule>
                <rule name="AdminBootstrap" stopProcessing="true">
                    <match url="admin/bootstrap-tagsinput-latest/(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="backend/web/bootstrap-tagsinput-latest/{R:1}" />
                </rule>
                <rule name="AdminJquery" stopProcessing="true">
                    <match url="admin/jQuery-Tags-Input-master/(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="backend/web/jQuery-Tags-Input-master/{R:1}" />
                </rule>
                <rule name="AdminCss" stopProcessing="true">
                    <match url="admin/css/(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="backend/web/css/{R:1}" />
                </rule>
                <rule name="AdminLadda" stopProcessing="true">
                    <match url="admin/ladda/(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="backend/web/ladda/{R:1}" />
                </rule>
                <rule name="AdminMedia" stopProcessing="true">
                    <match url="admin/media/(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="backend/web/media/{R:1}" />
                </rule>
                <rule name="AdminRewriteRequestsToPublic" stopProcessing="true">
                    <match url="^admin(.+)?$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="backend/web/index.php/{R:0}" />
                </rule>
                <rule name="Themes" stopProcessing="true">
                    <match url="^(.*)?(themes/front)(.*)?$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="frontend/web/{R:0}" />
                </rule>
                <rule name="Assets" stopProcessing="true">
                    <match url="assets/(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="frontend/web/assets/{R:1}" />
                </rule>
                <rule name="Ladda" stopProcessing="true">
                    <match url="ladda/(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="frontend/web/ladda/{R:1}" />
                </rule>
                <rule name="Foundation" stopProcessing="true">
                    <match url="foundation/(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="frontend/web/foundation/{R:1}" />
                </rule>
                <rule name="Css" stopProcessing="true">
                    <match url="css/(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="frontend/web/css/{R:1}" />
                </rule>
                <rule name="Media" stopProcessing="true">
                    <match url="media/(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="frontend/web/media/{R:1}" />
                </rule>
                <rule name="RewriteRequestsToPublic" stopProcessing="true">
                    <match url="^(.*)$" />
                    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    </conditions>
                    <action type="Rewrite" url="frontend/web/index.php/{R:0}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>