Php:使用 web.config 重写 URL

Php: Rewrite URL using web.config

这是我的第一个 PHP 应用程序,我正在使用 .html.php 本网站的页面。如果用户浏览 mysite.com/users/?abc123,它会成功加载 ID 为“abc123”的用户详细信息 [=54] =] 页面 mysite.com/users/index.html 通过 Ajax。现在,我的任务是从 URL 中删除 ?,这样如果用户浏览 mysite.com/users/abc123,那么 mysite.com/users/index.html?abc123 应该成功提供详细信息。

我遵循 this link 并将此规则添加到我的 web.config 中,但这似乎没有用,我收到了:

Error: HTTP Error 404.0 - Not Found

<rule name="Remove question mark" patternSyntax="Wildcard" stopProcessing="true">
  <match url="*" />
  <conditions>
    <add input="{HTTP_HOST}" pattern="^users/(.*)$" />
  </conditions>
  <action type="Redirect" url="users/?{R:0}" redirectType="Permanent" />
</rule>

请协助我解决以下问题:

  1. 我只能使用 web.config 进行 URL 重写(为简单起见)
  2. 我要重写 URL 的页面是 .HTML 而不是 .PHP(如果重要的话)
  3. 我正在 IIS 8 中本地测试我的 PHP 站点,配置为服务 PHP

这应该有效

<rule name="Remove question mark" stopProcessing="true">
  <match url="^/?users/([^/]+)$" 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="/users/index.html?{R:1}" />
</rule>