2

我正在尝试将.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>

提前致谢

4

2 回答 2

3

如果您从域的根目录 ( http://domain.tld/app.php ) 运行 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 Rewrite。所以我不知道那些的语法:)

于 2013-08-01T20:09:38.840 回答
0

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

于 2014-04-05T04:36:48.560 回答