David Gard
David Gard

Reputation: 12047

Configure Azure static website to not require a trailing slash

I have an Azure Storage Account configured as a static website. The static website contains a sub-directory called 'versions', which then contains several other versions of the website. I can display these versions, but it requires a trailing slash, which obviously isn't ideal as most people don't use them.

For example, say the URL of my static websits is https://mystorageaccount.z8.web.core.windows.net...

I'm assuming this is because the static website is attempting to serve https://mystorageaccount.blob.core.windows.net/%24web/versions/1.2.3index.html, but is there a way I can configure the static website to not require the trailing slash?

I did try to specify /index.html as the index document, but the static website configuration disallows that.

If specified, index document name must be between 3 and 255 characters in length, and must not contain any '/' characters.

Upvotes: 4

Views: 1813

Answers (2)

Jeff
Jeff

Reputation: 1

Ran into this problem today and the solution was create a rule in Azure Front Door to match any request path (URL portion after the host) that does not end in "/", does not end with a file extension, and is not empty (so it doesn't match a request to the root somesite.domain.com, which contains no request path). Then, do a URL redirect to the current request path plus a trailing "/".

Rule screenshot

Upvotes: 0

Ricker Silva
Ricker Silva

Reputation: 1135

I run into this issue a couple days ago and found this very old post unanswered so here are my 5 cents.

This is due to an error in Azure static web apps, wether they are inside a blob storage or in the not so shiny new static web apps services. That's why it was not relevant using or not the CDN services.

The problem in short words is that Azure static web apps dosn't add the trailing slash at the end of the url and this makes it impossible to link correctly the resources of the page (scripts, images, fonts, styles, anything), because it ends up looking folder in the parent folder.

The issue is explained here https://github.com/Azure/static-web-apps/issues/42

WORKAROUND

Make sure you add the trailing slash on any link or

Use absolute URLs instead of relative ones.

Upvotes: 1

Related Questions