IIS 7 Rewrite rule throws HTTP Error 403.14 - Forbidden if folder exists

Viewed 1232

I have one web site routed by php.

I have put this on web.config file:

<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>

It works ok for all my site routes, except if route match one existing directory.

I have this folders structure:

index.php
cursos/img
assets/img

My web site manage without problems routes like: /paginas, /paginas/contacto, cursos/masinformacion/10, cursos/img/banner.jpg, etc...

But if I try to goto /cursos i get: HTTP Error 403.14 - Forbidden

I have added these lines to web.config file:

<!-- 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>

And now it's:

<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>

But it still does not work. It looks like IIS tries to access the cursos folder before running the rewrite rules

1 Answers
Related