web.config 将所有请求路由到 index.php,物理文件和目录除外

web.config to route all request to index.php except for physical files and directories

我正在尝试将 php 脚本上传到 windows iis 服务器 在 php 脚本中,我们有一个 htacess 文件,它将所有请求路由到 index.php,因此我们可以

网站.com/something

而不是

site.com/index.php?/something

但它在 windows 服务器上不起作用,所以我试图找到 web.config 版本,这是我找到的

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <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>

        <!-- 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="false" />
          <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>
  </system.webServer>
</configuration>

它有点工作,但它不会加载静态文件(css,js)就像我去

site.com/public/js/jquery.js

我收到这个错误

HTTP Error 500.52 - URL Rewrite Module Error.
The page cannot be displayed because an internal server error has occurred.
Detailed Error Information
Module  RewriteModule
Notification    SendResponse
Handler StaticFile
Error Code  0x800700b7
Config Error    Cannot add duplicate collection entry of type 'rule' with unique key attribute 'name' set to 'Imported Rule 1'
Config File \?\C:\HostingSpaces\phoenarts\site.com\wwwroot\public\web.config

基本上它可以工作我需要告诉它忽略 link 目录和静态文件

该错误表明您已经在某处声明了一个名为 Imported Rule 1 的规则。尝试更改错误中指示的文件中的规则名称。

如果您在 ~/public 中有一个 web.config 文件,在 Web 根目录中有另一个文件,这两个文件将合并用于对您的静态资产的请求。这听起来像是发生了什么事?

您可以使用多个 web.config 来配置不同的路径,但您不应该在它们之间重复规则。

您还可以使用根 web.config 中的 <location> 元素来配置不同的路径(作为使用多个 web.config 文件的替代方法)。