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
HTTP Error 403.14 - Forbidden - The Web server is configured to not list the contents of this directory.
When adding a rewrite rules to a site it should save it in the site's web. config. One reason I can think of why you don't see it there, is that you added the rule on the server level rather than the site level. When done on the server level it is saved in the ApplicationHost.
Problem happened because of trailing slash.You can fix it in two steps:
1.Fix your regexp to ^cursos(\/?)$
2.Move this rule at first place:
<rule name="cursos redirect" stopProcessing="true">
<match url="^cursos(\/?)$" />
<action type="Rewrite" url="/index.php/{R:0}" appendQueryString="true" />
</rule>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With