Forcing HTTPS with Azure CDN - azure

I’m using Azure CDN in front of a Storage Account. I’m wanting to serve everything via HTTPS only, so I’ve setup HTTPS on the custom domain and created a URL rewrite:
But the problem is that I end up at a URL like this:
https://the-custom-domain/website/17/index.html
The website/17/index.html is the root content within the Storage Account, but I don’t know why it’s appending the container path before the filename. There’s also rewrite rule for static files (https://blog.lifeishao.com/2017/05/24/serving-your-static-sites-with-azure-blob-and-cdn).
Any idea what’s wrong with the URL rewrite?

There is an official guide from MS here, which works with standard Azure CDN:
https://learn.microsoft.com/en-us/azure/cdn/cdn-standard-rules-engine
Summary below:
Redirect users to HTTPS
On the CDN profile page, select the endpoint you want to create rules for.
Select the Rules Engine tab.
Select Add rule and enter a rule name.
To identify the type of requests the rule applies to, create a match condition:
Select Add condition, and then select the Request protocol match condition.
For Operator, select Equals.
For Value, select HTTP.
Select the action to apply to the requests that satisfy the match condition:
Select Add action, and then select URL redirect.
For Type, select Found (302).
For Protocol, select HTTPS.
Leave all other fields blank to use incoming values.
Select Save to save the new rule. The rule is now available to use.

I am using Azure Verizon Premium CDN.
I did two rules. The order of the rules matter. You will need to wait up to 4 hours after each test.
image remove index.html 2 continue as image 3
=============== END FIRST RULE ==================
here as text
1. redirect HTTP to HTTPs
rule--> (.*) destination https://%{host}/$1
remove remove index.html did not work 100% ;-(
URL Rewrite
2.A Source ((?:[^\?]/)?)($|\?.) -Destination -> $1index.html$2
2.B Source ((?:[^\?]/)?[^\?/.]+)($|\?.) -Destination - > $1/index.html$2

I'm using Azure Verizon Premium.
In this case you might want to redirect your http requests to your https endpoint. In this case you must add one rule for each endpoint you want this behavior:
match condition:
if Request Scheme = HTTP
feature:
Redirect - Code: 301, source: (.*), destination: https://%{host}/$1
This response was found at docs microsoft

It's a lot simpler now
No need to enter anything to the hostname, path etc..
Make sure that you have turned on both HTTP and HTTPS in the Origin Settings
It should reflect within 10minutes

I am using below configuration for redirecting any request to https
IF
Request Schema, HTTP
Feature
URL Redirect
Code: 301
Source: (.*)
Destination: https://%{host}/$1

If you want simple 1:1 http to https solution (without any unwanted) you should use following rule:
https://%{host}/%{request_uri#/}
IF
Request Schema, HTTP
Feature
URL Redirect
Code: 301
Source: (.*)
Destination: https://%{host}/%{request_uri#/}

Related

Azure Application Gateway Combined Path Based and Redirect rules

I want to modify my Azure Application Gwateway Path based and Redirect rules to exhibit the following behavior:
mygateway.com/test/* redirects to a website
mygateway.com/* forwards to a backend pool.
This is my current rule configuration but redirection is not occurring when I navigate to /test/*. Instead, all traffic is being routed to the /* path based rule.
Thank you!
The problem is the path based rule is being evaluated first since that is /*
everything is being sent there.
The way to fix it is to use the priority parameter to ensure that your redirect rule is evaluated first.
https://learn.microsoft.com/en-us/cli/azure/network/application-gateway/rule?view=azure-cli-latest

URL rewrite in Azure Front Door Premium

The rules engine identifies my intended URL fine via a condition. However the Action options - even though one says URL rewrite - only appear to allow rewrite of the path/URI. Not rewrite of the hostname.
If i wanted a rule that would always rewrite https://myhost.domain1.com/path to become myotherhost.domain2.com/path, how would i go about it?
In the FD Origin config, i have the option of setting 'origin host header' to be myotherhost.domain2.com. But that doesnt appear to be sufficient.
You want to retain the path but redirect to another host, so you need to use the URL redirect feature than the rewrite.
In the URL redirect, you can configure "Rule set" config wherein you can define the hostname for which this request need to be transferred by Front Door. There are nuances of what type of redirect code you use, based on your context[ and so accordingly you need to choose 302 or 307 and so on].
See the doc page for detailed step by step configuration in Azure portal.

How to Redirect a URL using Application Gateway with Query included and Path excluded

I am not able to successfully redirect a URL with query to another target external URL.
eg:-
Request URL:- http://example123.com/xxx/yy?path=com
Target URL:- http://example456.com/zzz/yy
Condition:-
I need to include the query string from the Request URL but not the Path.
I have tried using the path-based routing rule on the App GateWay with below configuration
Redirect rule
But after hitting save its going back to a state like this:
Rule after save
Can anyone please find us a solution ??
According to configuration-request-routing-rules (github.com) ,
Path based rule may not send path to query and only applies it to path of url.
When you create a rule, you choose between basic and path-based.
Choose basic if you want to forward all requests on the associated listener (for example, blog.contoso.com/*) to a single back-end pool.
Choose path-based if you want to route requests from specific URL paths to specific back-end pools. The path pattern is applied only to
the path of the URL, not to its query parameters.
Also see external-site | Microsoft Docs
Please check if you can try the rewriting URL path instead of redirecting which refers to this tutorial for implementation.

IIS dynamic URL rewrite

I'm trying in Microsoft IIS 10 to do dynamic URL rewrite / redirect based on a condition that the URL contains specific info.
Match URL / Pattern: mysite/pages/viewpage.action?uniqueurl
Rewrite URL: mysite.xyz.xyz/pages/viewpage.action?uniqueurl
What I want to achieve is that whatever you write after mysite/pages/viewpage.action? it needs to rewrite to the same URL just with mysite.xyz.xyz added instead of only mysite.
Example 1:
mysite/pages/viewpage.action?thisisexample1 -> mysite.xyz.xyz/pages/viewpage.action?thisisexample1
Example 2: mysite/pages/viewpage.action?anothersite -> mysite.xyz.xyz/pages/viewpage.action?anothersite
When I'm trying to set up the above in the URL rewrite section i just end up at: https://mysite.xyz.xyz/pages/viewpage.action.
I have a generel HTTP redirect aswell to https://mysite.xyz.xyz when you come from mysite which works fine but I need to try and get specific URL rewrites to work aswell.
I found the solution.
It was to add HTTP redirect parameters to the HTTP redirect and change the Redirect Behaviour.
I added $S$Q to the HTTP redirect which fixed the issue in the regards to the question mark in the redirect which IIS couldn't handle without the extra parameters.
Besides that I need to change the Redirect Behaviour so I put a checkmark in 'Redirect all requests to exact destination (instead of relative to destination)
Edit: Typo

IIS URL Rewrite for a folder to another web server

I have an IIS webserver running a website. I've installed ARR3 to enable routing rules.
I'd like to redirect all the incoming request for the URL .mydomain/url2redirect/ to an Apache server installed on the same machine where is running SVN.
So in the inbound rule definition I've inserted the following:
Input: URL path after '/'
Pattern: *.mydomain/url2redirect/*
Action Type: Rewrite
Action URL: https://ip-address:8080/{R:2}
By testing the pattern, I get the desired result, and in the R:2 back reference I get the requested page I need to pass to SVN, but I get always a 404.
"url2redirect" doesn't exist but it should captured by the URL rewrite and forwarded to the Action URL.
I've added any outbound rule. Should I have to add something? what?
I've tried also to add a Reverse Proxy Rule, using the ARR template but, it's completely ignored, therefore I think that the routing is not working at all on IIS.
As far as I know, the url rewrite rule Pattern doesn't match the domain part.
That means mydomain will not include in the Pattern.
If you want to match the url2redirect, you should use below pattern.
url2redirect(.*)
Then I suggest you could modify your action url as below:
https://ip-address:8080{R:1}

Resources