【问题标题】:Problems importing .htaccess into IIS URL Rewrite Web.Config将 .htaccess 导入 IIS URL Rewrite Web.Config 时出现问题
【发布时间】:2013-07-09 01:15:21
【问题描述】:

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

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

对于不了解 IIS 中的语法,我深表歉意。我附加了原始文件/web/.htaccess,为方便起见,不包括所有的cmets。

提前致谢

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>

提前致谢

【问题讨论】:

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


    【解决方案1】:

    如果您从域的根目录 (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 重写。所以我不知道那些语法:)

    【讨论】:

    • 如果我从根目录中运行,让我说 foo 我需要如何格式化规则才能以这种方式工作
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2012-11-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-03
      • 1970-01-01
      • 1970-01-01
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多