Srichakradhar
Srichakradhar

Reputation: 1625

Rewrite URL in Azure App Service Web.config to redirect root to index.html

How can I match the root url and redirect it to index.html? I have tried:

<rule name="SPA">
    <match url="^$" />
    <action type="Rewrite" url="index.html" />
</rule>

and

<rule name="SPA">
    <match url="" />
    <action type="Rewrite" url="index.html" />
</rule>

in Azure App Service. But they didn't work. I got: Cannot GET /

my Web.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="SPA">
                    <match url="^$" />
                    <action type="Rewrite" url="index.html" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

I tried Redirect as well. But no luck.

<rule name="Redirect to canonical url">
<match url="^$" >
<conditions>
   <!-- Check whether the requested domain is in canonical form -->
   <add input="{HTTP_HOST}" type="Pattern" pattern="^purchasehelper.azurewebsites.net$">
</conditions>
<!-- Redirect to canonical url and convert URL path to lowercase -->
<action type="Redirect" url="http://purchasehelper.azurewebsites.net/index.html" RedirectType="Found"/>
</rule>

Upvotes: 1

Views: 4125

Answers (1)

Swikruti Bose
Swikruti Bose

Reputation: 154

You can try to add and modify the following rewrite content in web.config file:

<?xml version="1.0" encoding="UTF-8"?>
 <configuration>
 <system.webServer>
 <rewrite>
 <rules>
<rule name="Index Request" enabled="true" stopProcessing="true">
 <match url="^$" />
 <action type="Redirect" url="index.html" logRewrittenUrl="true" />
 </rule>
</rules>
 </rewrite>
 </system.webServer>
 </configuration>

Upvotes: 3

Related Questions