簡體   English   中英

為什么在向Azure中的Web.config添加重寫規則時會獲得500?

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

我正在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>

但是當我在rules標簽內添加以下代碼時,我收到錯誤消息The page cannot be displayed because an internal server error has occurred 為什么?

<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 Illegal中。 重命名一條規則。

另請查看此節點(適用於調試):

<?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的東西都沒有。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM