简体   繁体   English

为什么在向Azure中的Web.config添加重写规则时会获得500?

[英]Why do I get a 500 when I add a rewrite rule to my Web.config in Azure?

I am deploying site on Azure, and I am trying to write rewrite rules for the site. 我正在Azure上部署站点,我正在尝试为该站点编写重写规则。

I have the following code, and it works: 我有以下代码,它的工作原理:

<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>

but when I add the following code inside of the rules tag I get the error message The page cannot be displayed because an internal server error has occurred . 但是当我在rules标签内添加以下代码时,我收到错误消息The page cannot be displayed because an internal server error has occurred Why? 为什么?

<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>

I assume that the first edition will not work. 我认为第一版不起作用。 The Second rule from the first edition is the same as the second edition. 第一版的第二条规则与第二版相同。

Your Problem is, that the Rules have the same name attribute Sendy all . 您的问题是,规则具有相同的名称属性Sendy all This is in the Web Config Illegal. 这是在Web Config Illegal中。 Rename one Rule. 重命名一条规则。

Also take a look at this node (Which is good for Debugging): 另请查看此节点(适用于调试):

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

Make sure, this is one of the first things in the web.config . 确保,这是web.config中的第一件事。 Then you would get the Error Code 500.52 with a detailed description, which is indicating this error. 然后你会得到错误代码500.52的详细描述,这表明这个错误。

By side the Problem, i don't get What you're Trying. 在问题的旁边,我没有得到你正在尝试的东西。 Consider to give the Request to your Index PHP: 考虑将请求提供给您的索引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>

If you call website.tld/api/IBar/DoFoo you can write: 如果你打电话给website.tld/api/IBar/DoFoo你可以写:

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

If you dont extract Details, and give them as Parameter, the whole Url Rewrite thing makes no sence. 如果你不提取细节,并将它们作为参数给出,那么整个Url Rewrite的东西都没有。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM