Why am I getting 500 when I add a rewrite rule to my Web.config in Azure?

I am deploying a site on Azure and I am trying to write rewrite rules for a 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 the rule 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> 
+7
php web-config .htaccess rewrite azure
source share
1 answer

I assume 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 attribute on the name Sendy all . This is in the Illegal web configuration. 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 to do in web.config . You will then receive an error code 500.52 with a detailed description that indicates this error.

Gradually the problem, I do not understand what you are trying. Think to query your PHP index:

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

Unless you retrieve the Details and specify them as a Parameter, the entire link to Url Rewrite has no meaning.

+2
source share

All Articles