Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewriting a URL in an Azure web app

I have a simple wildcard routing rule I want to apply for my Azure web app.

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

Do I have any option here given I can't RDP into the machine and fiddle with IIS? This is not an ASP.Net website, it's a simple SPA application.

like image 993
Mister Epic Avatar asked Apr 14 '16 17:04

Mister Epic


People also ask

How do I change my Azure webapp URL?

Under Azure App Home page for your app., scroll down on left to "Developer tools" - Select Clone app. Add a new URL and update area etc. You can then go and add your custom domain after, etc.

Which URL must be used to manage the Azure Web Apps?

When you create a new website by using Web Apps in Azure, a default sitename.azurewebsites.net domain is assigned to your site. If you add a custom host name to your site and don't want users to be able to access your default *. azurewebsites.net domain, you can redirect the default URL.


2 Answers

You need to create a web.config file in your wwwroot folder and put the relevant config entries there.

Here's an example of an web.config rule, to give you an idea of what it should look like.

The below example redirect the default *.azurewebsites.net domain to a custom domain (via http://zainrizvi.io/blog/block-default-azure-websites-domain/)

<configuration>
  <system.webServer>  
    <rewrite>  
        <rules>  
          <rule name="Redirect rquests to default azure websites domain" stopProcessing="true">
            <match url="(.*)" />  
            <conditions logicalGrouping="MatchAny">
              <add input="{HTTP_HOST}" pattern="^yoursite\.azurewebsites\.net$" />
            </conditions>
            <action type="Redirect" url="http://www.yoursite.com/{R:0}" />  
          </rule>  
        </rules>  
    </rewrite>  
  </system.webServer>  
</configuration>
like image 98
Zain Rizvi Avatar answered Oct 23 '22 22:10

Zain Rizvi


If simply want all URL's that resolve to this server & site to redirect to index.html you could use this rewrite section:

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="SPA">
                    <match url=".*" />
                    <action type="Rewrite" url="index.html" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

This is very similar to what you have except some minor syntax fixes e.g. the pattern should be ".*" and the rewrite URL target simply "index.html". Note this means that ALL URL's to your site will be rewritten, even for other resources like CSS and JS files, images etc. So you'd better be fetching your resources from other domains.

like image 7
Tian van Heerden Avatar answered Oct 24 '22 00:10

Tian van Heerden