【发布时间】: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 文件夹
【问题讨论】: