Search code examples
azureweb-config

How do I define static files as routes on an Azure Static Website?


My use case is a static azure website with deep linking. I would like for my azure site to return my index.html page when certain URLs are called e.g. /t/2

I can do this when using ASP.NET to serve the application by adding the following into my Route

routes.MapRoute(
            name: "DeepLink",
            url: "t/{*id}",
            defaults: new { controller = "Home", action = "Index" }
        );

I would like to achieve the same but with a static site. I can add in a Web.config which I can use to redirect/rewrite my url but I want the URL to stay as /t/2 so the front end can react to it.


Solution

  • Using the 404 page as a fallback isn't the most recommended way of routing your links.

    You can use a routes.json file, as described here.

    You can use wildcards if needed. Your routes.json file would look something like this:

    {
       "route": "/t/2",
       "serve": "/index.html",
    }