将.htaccess导入IIS URL重写Web.Config时出现问题



我正在尝试将.htaccess文件导入IIS 7中的URL重写规则。

Symfony 2中的当前文件无法将其导入IIS。我需要知道语法的人的帮助,将文件翻译成IIS可用的文件,并呼吁这项工作将帮助任何未来在IIS中使用Symfony 2的用户。

我很抱歉不知道IIS中的语法。并且我附加原始文件/web/.htaccess,为了方便而排除所有注释。

提前感谢

DirectoryIndex app.php
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]
    RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /app.php/
    </IfModule>
</IfModule>

当前的错误输出是:

<rewrite>
  <rules>
    <!--The rule cannot be converted into an equivalent IIS format because of unsupported flags: E-->
    <!--This rule was not converted because it contains references that are not supported: 'ENV::BASE'-->
    <rule name="Imported Rule 3" stopProcessing="true">
      <match url=".?" ignoreCase="false" />
      <conditions>
        <!--# If the requested filename exists, simply serve it.-->
        <!--# We only want to let Apache serve files and not directories.-->
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
      </conditions>
      <action type="None" />
    </rule>
    <!--This rule was not converted because it contains references that are not supported: 'ENV::BASE'-->
  </rules>
</rewrite>

提前感谢

如果从域的根运行app.php(http://domain.tld/app.php)则可以删除ENV:BASE变量。这将导致在IIS中导入以下XML:

<rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^app.php(/(.*)|$)" ignoreCase="false" />
      <action type="Redirect" redirectType="Permanent" url="/{R:2}" />
    </rule>
    <rule name="Imported Rule 2" stopProcessing="true">
      <match url=".?" ignoreCase="false" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
      </conditions>
      <action type="None" />
    </rule>
    <rule name="Imported Rule 3" stopProcessing="true">
      <match url=".?" ignoreCase="false" />
      <action type="Rewrite" url="/app.php" />
    </rule>
  </rules>
</rewrite>

编辑:从一个子目录这应该工作,我相信(子目录是"foo"):

<rewrite>
  <rules>
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^app.php(/(.*)|$)" ignoreCase="false" />
      <action type="Redirect" redirectType="Permanent" url="foo/{R:2}" />
    </rule>
    <rule name="Imported Rule 2" stopProcessing="true">
      <match url=".?" ignoreCase="false" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" />
      </conditions>
      <action type="None" />
    </rule>
    <rule name="Imported Rule 3" stopProcessing="true">
      <match url=".?" ignoreCase="false" />
      <action type="Rewrite" url="foo/app.php" />
    </rule>
  </rules>
</rewrite>

使用变量可能有更好的方法,但我只使用了从mod_Rewrite导入的IIS URL重写。所以我不知道这些的语法:)

或者您可以安装isapi rewrite-无需翻译-http://www.helicontech.com/isapi_rewrite/

最新更新