php - 当我向 Azure 中的 Web.config 添加重写规则时,为什么会收到 500 错误?

标签 php .htaccess azure web-config url-rewriting

我正在 Azure 上部署站点,并且正在尝试为该站点编写重写规则。

我有以下代码,它可以工作:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Sendy all" stopProcessing="true">
          <match url="^(.+?)$" ignoreCase="true" />
             <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
             </conditions>
          <action type="Rewrite" url="index.php" appendQueryString="true" />
        </rule>
        <rule name="Sendy all" stopProcessing="true">
          <match url="^api/(.+?)$" ignoreCase="true" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            </conditions>
          <action type="Rewrite" url="index.php" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

但是当我在规则标记内添加以下代码时,我收到错误消息由于发生内部服务器错误,无法显示页面。为什么?

<rule name="Sendy all" stopProcessing="true">
  <match url="^api/(.+?)$" ignoreCase="true" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    </conditions>
  <action type="Rewrite" url="index.php" appendQueryString="true" />
</rule>

最佳答案

我认为第一版不会工作。第一版的第二条规则与第二版相同。

您的问题是,规则具有相同的名称属性Sendy all。这在 Web Config 中是非法的。重命名一条规则。

另外看看这个节点(这对于调试有好处):

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
    <system.webServer>
        <httpErrors errorMode="Detailed" />
    </system.webServer>
</configuration>

确保这是 web.config 中的首要内容之一。然后您将收到错误代码 500.52 以及详细说明,表明此错误。

除了问题之外,我不明白你在尝试什么。考虑向您的索引 PHP 发出请求:

    <rule name="Sendy all" stopProcessing="true">
      <match url="^api/(.+?)$" ignoreCase="true" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
          <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        </conditions>
      <action type="Rewrite" url="index.php?api=1&amp;request={R:1}" appendQueryString="true" />
    </rule>

如果您调用website.tld/api/IBar/DoFoo,您可以编写:

$isApi = isset($_GET['api']); //Was the API Rule Affected?
$request = isset($_GET['request']) ? $_GET['request'] : ''; //"IBar/DoFoo"

如果您不提取详细信息,并将它们作为参数提供,则整个 Url Rewrite 事情就没有意义。

关于php - 当我向 Azure 中的 Web.config 添加重写规则时,为什么会收到 500 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18006125/

相关文章:

php - 通过导入将图像上传到xampp中的数据库

php - Laravel 5.2 CORS,GET 不使用预检选项

php - 使用接口(interface)时如何定义关系

c# - 如何在 Visual Studio Code 调试期间传递 Azure KeyVault 的访问 token

php - 想知道 Wordpress 的默认发布日期 PHP 字符串是什么?

.htaccess - htaccess 重写规则不起作用

php - Yii 2.0 从 URL 中隐藏/basic/web 以及 index.php

php - htaccess 将子文件夹重定向到子域而不更改 url

windows - 如何使用 Packer 在 Azure 中构建具有大文件的镜像?

azure - 使用 Powershell,如何向 azure api 管理 API 添加版本?