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

时间:2013-07-10 22:22:33

标签: apache iis mod-rewrite symfony url-rewrite-module

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

提前致谢

2 个答案:

答案 0 :(得分: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>

编辑:从一个子目录,这应该工作,我相信(subdir是“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>

对于变量可能有更好的方法,但我只使用IIS URL Rewrite和mod_rewrite导入。所以我不知道那些的语法:)

答案 1 :(得分:0)

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