微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 IIS URL 重写器将 .htaccess 重写为 web.config

如何解决使用 IIS URL 重写器将 .htaccess 重写为 web.config

我想使用带有 IIS 的 Windows Server 发布 Laravel 项目。

当我尝试使用来自 IIS 的 URL 重写器将 .htaccess 文件重写为 web.config 文件时,我收到以下错误

No se puede convertir la regla en un formato de IIS equivalente porque contiene marcas no admitidas: E-->

.htaccess 文件包含以下内容

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.PHP [L]
</IfModule>

我得到的 XML 文件如下:

<rewrite>
  <rules>
    <!--No se puede convertir la regla en un formato de IIS equivalente porque contiene marcas no admitidas: E-->
    <rule name="Regla 2 importada" stopProcessing="true">
      <match url="^" ignoreCase="false" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
        <add input="{URL}" pattern="(.+)/$" ignoreCase="false" />
      </conditions>
      <action type="Redirect" redirectType="Permanent" url="{C:1}" />
    </rule>
    <rule name="Regla 3 importada" stopProcessing="true">
      <match url="^" ignoreCase="false" />
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
      </conditions>
      <action type="Rewrite" url="index.PHP" />
    </rule>
  </rules>
</rewrite>

如您所见,第一个规则是导致问题的规则。出于某种原因,它不允许在 RewriteRule 上使用字符“E”。

我对这个主题了解不多,但因此我无法应用该规则,唯一的方法是消除 .htaccess 上的第一条规则,但我确信它会导致问题我的应用在未来。

¿我该如何解决这个问题?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。