Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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. 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>
like image 310
bogdaniy Avatar asked Aug 01 '13 23:08

bogdaniy


1 Answers

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. This is in the 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. Then you would get the Error Code 500.52 with a detailed description, which is indicating this error.

By side the Problem, i don't get What you're Trying. Consider to give the Request to your Index 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:

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

like image 124
Christian Gollhardt Avatar answered Sep 27 '22 19:09

Christian Gollhardt