Reputation: 524
I'm trying to host an Angular
project with Azure Storage Static Website
through Azure CDN Verizon Premium
Let's say i have containers for each Angular
builds named like v0.3.13.3
and in that container there are also multi language builds of angular project.
What i'm trying to achieve is to serve the right index.html
with correct routing for each version and language.
You may find example routes below:
my.domain.com/v0.3.13.3
should serve /v0.3.13.3/index.html
my.domain.com/v0.3.13.3/dashboard
should serve /v0.3.13.3/index.html
my.domain.com/v0.3.13.3/fr
should serve /v0.3.13.3/fr/index.html
my.domain.com/v0.3.13.3/fr/dashboard
should serve /v0.3.13.3/fr/index.html
I've managed to do it with Azure Standard Rules Engine
like the screen shot below.
But as far as i've seen from the docs, in standard rules engine Contains
field can't be filled with regex. I've digged all over google but can't seem to find any solution that suits me.
So i've switched my CDN service to Verizon Premium and tried to apply (v(?:(\d+)\.)?(?:(\d+)\.)?(?:(\d+)\.\d+))
to path regex.
The main issue i'm having with Verizon Premium is that i can only apply URL Rewrite
feature if i state my IF field to Always
As you can see URL Rewrite
is not listed.
Also i've made couple of deployments using Always
statement but they did not any good.
The single example that everyone shares in their blogs
So above example does not cover File Extensions and sub routes.
Are there any ways to achieve my goal?
Thanks in advance.
Upvotes: 5
Views: 2337
Reputation: 139
I had a bear of a time on this issue in March 2022 using V4 of the rules engine. I finally got the redirect to work by duplicating the redirects to account for both hashes for the origin server, starting with 00 and 08 in my case. It feels like the CDN is using a blue/green deployment methodology, and each time you deploy, it switches to the other server.
So if you deploy using the hash starting with 00, it will move your deployment to the 08 server.
Then you attempt to deploy using the 08 hash, and the system complains you haven't changed anything. :)
So I just duplicated code and cried into my pillow at night.
For the record, if you attempt to deploy in the "feature.url.url-redirect source" section using a regex containing something like /[0-9]+ when you change the draft into a policy, the system will complain that the source does not match any known origin.
This is what worked for me. If someone has a more elegant solution, I welcome it!
<policy>
<rules>
<rule>
<description>Redirect HTTP to HTTPS 00 Version</description>
<match.request.request-scheme.literal value="http">
<feature.url.url-redirect source="/00XXXXXX/www-example-com/(.*)" destination="https://%{host}/$1" code="302"/>
</match.request.request-scheme.literal>
</rule>
<rule>
<description>Redirect HTTP to HTTPS 80 Version</description>
<match.request.request-scheme.literal value="http">
<feature.url.url-redirect source="/80XXXXXX/www-example-com/(.*)" destination="https://%{host}/$1" code="302"/>
</match.request.request-scheme.literal>
</rule>
<rule>
<description>Site redirects to 00 Version</description>
<match.request.request-scheme.literal value="https">
<select.first-match>
<match.url.url-path.regex result="match" value="[\/#]*\/dir1\/subdir1.*" ignore-case="true" encoded="false">
<feature.url.url-redirect source="/00XXXXXX/www-example-com/.*" destination="https://www.example.com/#/dir1/subdir1" code="302"/>
</match.url.url-path.regex>
<match.url.url-path.regex result="match" value="[\/#]*\/folder2\/subfolder2.*" ignore-case="true" encoded="false">
<feature.url.url-redirect source="/00XXXXXX/www-example-com/.*" destination="https://www.example.com/#/folder2/subfolder2" code="302"/>
</match.url.url-path.regex>
<match.url.url-path.regex result="match" value=".*" ignore-case="true" encoded="false">
<feature.url.url-redirect source="/00XXXXXX/www-example-com/.*" destination="https://www.example.com/" code="302"/>
</match.url.url-path.regex>
</select.first-match>
</match.request.request-scheme.literal>
</rule>
<rule>
<description>Site redirects to 80 Version</description>
<match.request.request-scheme.literal value="https">
<select.first-match>
<match.url.url-path.regex result="match" value="[\/#]*\/dir1\/subdir1.*" ignore-case="true" encoded="false">
<feature.url.url-redirect source="/80XXXXXX/www-example-com/.*" destination="https://www.example.com/#/dir1/subdir1" code="302"/>
</match.url.url-path.regex>
<match.url.url-path.regex result="match" value="[\/#]*\/folder2\/subfolder2.*" ignore-case="true" encoded="false">
<feature.url.url-redirect source="/80XXXXXX/www-example-com/.*" destination="https://www.example.com/#/folder2/subfolder2" code="302"/>
</match.url.url-path.regex>
<match.url.url-path.regex result="match" value=".*" ignore-case="true" encoded="false">
<feature.url.url-redirect source="/80XXXXXX/www-example-com/.*" destination="https://www.example.com/" code="302"/>
</match.url.url-path.regex>
</select.first-match>
</match.request.request-scheme.literal>
</rule>
</rules>
Upvotes: 0
Reputation: 418
I would share my current config that I using in Verizon Premium in Rule V4: The steps are:
/80XXXXXX/XXXXXX/((?:[^\?]*/)?)($|\?.*)
/80XXXXXX/XXXXXX/index.html$2
/80XXXXXX/XXXXXX/((?:[^\?]*\/)?[^\?\/.]+)($|\?.*)
/80XXXXXX/XXXXXX/index.html$2
Also you can obtainer the origin as described in here https://stackoverflow.com/a/58700538/3591687
This is the XML Rule was generated
<policy>
<rules>
<rule>
<match.always>
<feature.url.url-rewrite source="/80XXXXXX/XXXXXX/((?:[^\?]*/)?)($|\?.*)" destination="/80XXXXXX/XXXXXX/index.html$2"/>
<feature.url.url-rewrite source="/80XXXXXX/XXXXXX/((?:[^\?]*\/)?[^\?\/.]+)($|\?.*)" destination="/80XXXXXX/XXXXXX/index.html$2"/>
</match.always>
</rule>
</rules>
</policy>
I hope that helps to somebody
Upvotes: 5
Reputation: 154
Please see below in Rules Engine 4.0 as to how you select the URL Rewrite in Azure CDN - the documentation is currently lacking and still attempting to get this to work. I will update this post once it is set up correctly
Upvotes: 0