从htaccess中的.config转换重定向

时间:2018-12-21 10:17:56

标签: xml .htaccess url-rewriting

我正在尝试在htaccess中转换此代码。我尝试了一些方法,但没有一个起作用。请帮助我将此代码隐藏到htaccess中。

<system.webServer>
    <rewrite>
      <rules>
        <rule name="RewriteRules" stopProcessing="true">
          <match url=".*" />
          <conditions logisticalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />

          </conditions>
          <action type="Rewrite" url="/index.html" />

        </rule>
      </rules>
    </rewrite>

  </system.webServer>

1 个答案:

答案 0 :(得分:0)

该问题中的IIS配置指出,对于任何请求,该请求都不会映射到文件,也不会映射到目录,并且所请求的URL路径路径未开始/api,然后将请求重写为{ {1}}。

这可以在Apache /index.html中使用mod_rewrite来实现,如下所示:

.htaccess

但是,RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule !^api /index.html [L] (纯HTML源文件)能够开箱即用地处理这种请求是不寻常的。

这是一个合理的标准“前控制器”模式,只有一个例外。