【问题标题】:How to convert this htaccess to iis web.config?如何将此 htaccess 转换为 iis web.config?
【发布时间】:2019-10-23 07:27:07
【问题描述】:

为什么当我通过 IIS 管理器使用 IIS web.config 自动转换 .htaccess > 重写 URL 这显示 404 错误

如何手动将其转换为 web.config?

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^(install)($|/) - [L]
    RewriteRule ^$ app/webroot/ [L]
    RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

这是使用 IIS 管理器 (web.config) 的结果

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1" stopProcessing="true">
                    <match url="^(install)($|/)" ignoreCase="false" />
                    <action type="None" />
                </rule>
                <rule name="Imported Rule 2" stopProcessing="true">
                    <match url="^$" ignoreCase="false" />
                    <action type="Rewrite" url="/app/webroot/" />
                </rule>
                <rule name="Imported Rule 3" stopProcessing="true">
                    <match url="(.*)" ignoreCase="false" />
                    <action type="Rewrite" url="/app/webroot/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

【问题讨论】:

    标签: .htaccess iis


    【解决方案1】:

    404 错误的子状态码是什么?因为 404.0 和 404.19 是不同的错误。您可以在 C:\inetpub\logs\LogFiles 中找到它。

    看起来规则已经正确转换了。

    Rule1 将扫描传入的 URL domain.com/install/domain.com/install 并防止这些 URL 被重写。

    Rule2 会将 domain.com 重写为 domain.com/app/webroot/

    例如,Rule3 将重写任何传入规则。 domain.com/a.aspxdomain.com/app/webroot/a.aspx

    那么这些规则是否满足您的要求?

    承诺重写可以在没有确保的情况下进行处理

    1.请确保请求已发送到您的 IIS 服务器。有时网络问题会将请求路由到另一台服务器并返回 404 错误。

    2.请确保domain.com/app/webroot/或domain.com/app/webroot/(.*)等目标URL可以正常访问。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-22
      • 2012-01-30
      • 1970-01-01
      • 2014-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多