Azure CDN - Dynamic URL Path rewrite - azure

I want to rewrite URLs for my static API to match the accordingly named files on my blob storage (at the moment static website with $web directory, files are in /api folder), e.g.:
/api/universities --> /api/universities.json
/api/universities/1 --> /api/universities/1.json
I have tried configuring a CDN Rule for it. But I can't get it to work, anyone who can help? Docs are really thin on variables for URL Rewriting with Azure CDN.

Related

"WebContentNotFound" error with azure static web

I have made a storage account then enabled static website then added the html file (plus everything else i need). once everything was added into the $web i copy pasted the give url and i get a 404 error as follows:
The requested content does not exist.
HttpStatusCode: 404
ErrorCode: WebContentNotFound
RequestId : 23ac6dc2-401e-0044-7797-b2e9c5000000
TimeStamp : 2021-09-26T05:29:47.2306494Z
i have used azure before for another school project and that website worked fine. i tried uploading those files in a new storage account and they gave me the same error but the website i made 6 months ago still works. naturally i thought well if this storage account still works then i will just put the new files in here and delete this website since its not needed anymore. tried and it gave me the same error so i changed it back to the original and now i get the error with those files too. any help would be amazing.
Azure blob storage doesn’t know to route requests to /OurWebPage through our index.html it only knows to route to index.html when requests are made to the base URL as we configured the default document. This means search crawlers and anyone linking directly to a page will get this error
Here we need to use Azure CDN, with this we can configure URL rewrites.
We can create CDN resource with Standard Microsoft tier. Refer to the blog for more insights.

Is there a way to add "X-Robots-Tag: noindex" header to pdf files served on Azure CDN

Just wondering if there is a way to add the "X-Robots-Tag: noindex" tag specifically to PDFs that are served from azure blob storage via an azureedge CDN url. For example -
Blob Storage URL - {subdomain}.blob.core.windows.net/container/test.pdf
CDN URL - {subdomain}.azureedge.net/container/test.pdf
I have read in some places that a way to do this is to add a robots.txt file to the $root container on the blob storage and set "Disallow: *.pdf", however it states that this is not completely reliable and I would rather set the X-Robots-Tag header. Is there a way in azure portal to set it up so that any "*.pdf" file being requested via either the blob or CDN url automatically has this header added to the response?
Many thanks in advance
You can find the CDN rule engine here(I am using Standard Microsoft tier):
Test result:

how to open Azure Blob url with index.html

i have an Angular web site built and hosted as a static website on in Azure Blob storage.
url looks like this.
https://xxxx.blob.core.windows.net/yyyy/index.html
when i navigate to the url it works fine. but then browser strips out "index.html" and if user refreshes the page url gets invalidated. is there a way to get make a url as such that it opens correctly with or without .html
but then browser strips out "index.html"
No, the browser does not change the URI at all. There is nothing in HTTP that says index.html is implicit in a URI.
Follow these instructions for setting up a static website in Azure Blob storage:
https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website-how-to
https://learn.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website
Specifically:
Use the {accountName}.{misc}.web.core.windows.net host-name (you can configure a custom hostname separately). Do not use the blob's direct URIs ({accountName}.blob.core.windows.net)
Your file blobs must be located in a container named $web (which will be mapped to your .web.core.windows.net root).
To specify the default-document (index document), i.e. the name of the blob that will be served when a blob filename is not specified, use the az command-line or Enable-AzStorageStaticWebsite PowerShell to specify --index-document index.html or whatever your website needs (e.g. Default.html, Index.htm, etc).

Azure CDN: How to URL Rewrite for specific page

I have an Azure CDN profile resource with Premium Verizon tier which allows customization for Rule Engine
Created an endpoint which serves from a URL https://test-cdn1.azureedge.net the content from a storage account which is mapped as the origin to blob container in storage account with origin path pointing to blob container name /blob-container
I am trying to add Rewrite rules (in HTTP Large Object Rules Engine Section) for specific two pages
https://test-cdn1.azureedge.net/main.js URL should rewrite to https://test-cdn1.azureedge.net/js/main.d20ff936.chunk.js
This file is at /blob-container/js/main.d20ff936.chunk.js
https://test-cdn1.azureedge.net/main.css URL should rewrite to https://test-cdn1.azureedge.net/css/main.cb03e.chunk.css
This file is at /blob-container/css/main.cb03e.chunk.css
https://test-cdn1.azureedge.net/vendor.js URL should rewrite to https://test-cdn1.azureedge.net/js/js/1.77a25e9f.chunk.js
This file is at /blob-container/js/js/1.77a25e9f.chunk.js
Here is a screenshot of what I have added at hte momement and is not working.
Also for any other URL request, I wish to give back a plain old empty 404 - Not Found.
Need help, thanks
I know the problem now, solved it by a few tries, it does take some time to get effective though.
The source and destination entries are the mapped folder path to the resource, so in above the three entry would be
Source: blob-container/main.js, Destination: blob-container/js/main.d20ff936.chunk.js
Source: blob-container/main.css, Destination: blob-container/css/main.cb03e.chunk.css
Source: blob-container/vendor.js, Destination: blob-container/js/1.77a25e9f.chunk.js
Still look for a way to return 404 Not Found for all other CDN path URL fetches

How to redirect HTTP requests to Azure Blob Storage base urls?

We have a Blob Storage baseurl like this:
https://mycompany.blob.core.windows.net/myprod
.. which has several files and folders inside it.
Now, when at some point an app (not in our control) makes a HTTP request to the above URL, which now returns a 404 not found (this is Blob Storage behavior; accessing the files inside the base url is fine).
And this causes things to blow up in our setup!
So, to workaround this, we want to listen through webhooks the HTTP request made to the baseurl above (only the baseurl, not when HTTP requests are made to files inside it) and return a 200 from an Azure Function.
Is this possible and how?
You cannot intercept calls pointing directly to blob storage. That DNS name (yourname.blob.core.windows.net) routes directly to Azure Blob Storage.
If you specifically need to intercept calls, then you need to route them to a dns name of your app (e.g. yourname.azurewebsites.net or yourname.com mapping to yourname.azurewebsites.net, if it's a web app). At this point, you could redirect to whatever you want (including blob storage URI's).
Note: Any blob URI you redirect to either needs to be public-accessible or have a Shared Access Signature (or policy) for your client app to get to it, otherwise a 404 will result.

Resources