【问题标题】:IIS 7 Rewrite rule throws HTTP Error 403.14 - Forbidden if folder existsIIS 7 重写规则引发 HTTP 错误 403.14 - 如果文件夹存在则禁止
【发布时间】:2018-01-05 18:30:06
【问题描述】:

我有一个通过 php 路由的网站。

我已将它放在 web.config 文件中:

<rewrite>
  <rules>

    <!-- Quitar los slash '/' del final de la ruta -->
    <rule name="RewriteRequestsToPublic">
      <match url="^(.*)$" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
      </conditions>
      <action type="Rewrite" url="/{R:0}" />
    </rule>

    <!-- la ruta /cursos/ directamente la redirigimos para que no dé error 403.14 al intentar 'explorar' el directorio -->
    <rule name="cursos redirect" stopProcessing="true">
      <match url="^cursos$" />
      <action type="Rewrite" url="/index.php/{R:1}" appendQueryString="true" />
    </rule>

    <!-- Si el archivo o carpeta solicitado no existe, se realiza la petición a través de index.php -->
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="true" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      </conditions>
      <action type="Rewrite" url="/index.php/{R:1}" appendQueryString="true" />
    </rule>
  </rules>
</rewrite>

它适用于我的所有站点路由,除非路由匹配一个现有目录。

我有这个文件夹结构:

index.php
cursos/img
assets/img

我的网站管理没有问题的路线,如:/paginas、/paginas/contacto、cursos/masinformacion/10、cursos/img/banner.jpg 等...

但如果我尝试转到 /cursos,我会得到:HTTP 错误 403.14 - 禁止

我已将这些行添加到web.config 文件中:

<!-- la ruta /cursos/ directamente la redirigimos para que no dé error 403.14 al intentar 'explorar' el directorio -->
<rule name="cursos redirect" stopProcessing="true">
  <match url="^cursos$" />
  <action type="Rewrite" url="/index.php/{R:1}" appendQueryString="true" />
</rule>

现在是:

<rewrite>
  <rules>

    <!-- Quitar los slash '/' del final de la ruta -->
    <rule name="RewriteRequestsToPublic">
      <match url="^(.*)$" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
      </conditions>
      <action type="Rewrite" url="/{R:0}" />
    </rule>

    <!-- la ruta /cursos/ directamente la redirigimos para que no dé error 403.14 al intentar 'explorar' el directorio -->
    <rule name="cursos redirect" stopProcessing="true">
      <match url="^cursos$" />
      <action type="Rewrite" url="/index.php/{R:1}" appendQueryString="true" />
    </rule>

    <!-- Si el archivo o carpeta solicitado no existe, se realiza la petición a través de index.php -->
    <rule name="Imported Rule 1" stopProcessing="true">
      <match url="^(.*)$" ignoreCase="true" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      </conditions>
      <action type="Rewrite" url="/index.php/{R:1}" appendQueryString="true" />
    </rule>
  </rules>
</rewrite>

但它仍然不起作用。看起来 IIS 在运行重写规则之前尝试访问 cursos 文件夹

【问题讨论】:

    标签: php iis iis-7 rules


    【解决方案1】:

    由于斜杠出现问题。您可以分两步解决它:

    1.将您的正则表达式修复为^cursos(\/?)$

    2.将此规则移到首位:

    <rule name="cursos redirect" stopProcessing="true">
      <match url="^cursos(\/?)$" />
      <action type="Rewrite" url="/index.php/{R:0}" appendQueryString="true" />
    </rule>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-17
      • 2013-03-18
      • 1970-01-01
      • 2013-04-24
      • 2014-05-01
      • 2023-03-26
      • 2014-08-22
      • 1970-01-01
      相关资源
      最近更新 更多