【问题标题】:How to hide subfolder from url addresses on IIS (RewriteRule)?如何从 IIS(RewriteRule)上的 url 地址隐藏子文件夹?
【发布时间】:2016-06-13 11:52:26
【问题描述】:

我正在尝试使用 IIS 从 Windows 服务器上的 URL 中删除 /frontend/web/backend/web web.config 作为 .htaccess

的替代品

我需要转换为 web.config 的原始 .htaccess 文件:

Options FollowSymlinks
RewriteEngine on
RewriteRule ^admin(.+)?$ backend/web/$1 [L,PT]
RewriteRule ^(.*)$ frontend/web/$1 [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 的网址。

【问题讨论】:

    标签: php .htaccess iis web-config


    【解决方案1】:

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

    像这样:

    <?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>
    

    【讨论】:

      猜你喜欢
      • 2017-11-01
      • 2015-04-09
      • 2018-09-18
      • 2017-06-06
      • 2015-03-31
      • 2014-01-09
      • 2014-06-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多