Routing for specific files in Azure front Door - azure-front-door

I have an application which if fronted with Azure Front Door. I need to add a robots.txt to the root of the domain and cannot host that within the application.
I was hoping to add the robots.txt to a storage blob /robots/robots.txt and setup a new route for /robots.txt and an origin of /robots/robots.txt but this appears as /robots/robots.txt/robots.txt in the back end.
What do I set the origin path to to find the correct file?

Unfortunately, any matched pattern is replaced by the origin path, this apparently includes file names. To go around this in this scenario, we can use a URL rewrite rule instead.
Origin Group configuration
Pattern to match: /robots.txt
Origin path: /
Rule Set Rules:
Action: URL Rewrite
Source pattern: /
Destination: /robots/robots.txt
Preserve unmatched path: No

Related

Azure Front Door route to app service subdirectory

I have an Azure Front Door environment that I would like to use to route a domain to an app service sub directory. But im having some issues setting it up
Domain: portal.example.com
Back End Pool: App Service - xxx.azurewebsites.net
I would like portal.example.com to route to xxxx.azurewbesites.net/portal
But for some reason im not able to do that and getting errors if i try to have it redirect with the slash " / "
"The domain and subdomains can be between 1 to 63 alphanumeric characters, must start and end with an alphanumeric character, and additionally can contain the '-' character in between. The top level domain must be between 2 to 61 alphabetical characters."
I have tried creating a routing rule and also tried using rule engine configuration.
seems there will be wrong route configuration. I have tried to replicate the same scenario.
Step1:
Created a front door environment with backend endpoint as
*****.azurewebsites.net
Step2:
Applying rule configuration to update route rule as
if request URL is "portal.example.com" then route the traffic to xxxx.azurewbesites.net/portal
refer this tutorial for more information. Found another similar post for reference.

Traefik redirect from one host to another

We decided to move from the subdomain structure to one root domain with path prefixes, but we got many old URLs on the internet. So is there any way to add a redirect from the old URL to the new one?
For example,
We got subdomain test.example.com switched to example.com/test, I can access correctly site with the string in docker-swarm YAML file
traefik.frontend.rule: Host:example.com;PathPrefixStrip:/test
but when I'm trying to add to Traefik config redirects like:
[http.middlewares]
[http.middlewares.test-redirectregex.redirectRegex]
regex = "^https://(*).example.com/)"
replacement = "^https://example.com/${1}"
Traefik says that it doesn't know where to forward this request
If I'm trying to add:
traefik.frontend.rule: Host:test.example.com,example.com;PathPrefixStrip:/test
Traefik adds a prefix to both hosts. Is there any way to resolve this without adding a second reverse proxy?
Assuming that you are using Traefik 2.1, you can use the below middleware for Traefik
[http.middlewares]
[http.middlewares.blog-redirect.redirectRegex]
regex = "^(https?://)(.*).example.com/(.*)$"
replacement = "${1}example.com/${2}/${3}"
permanent = true
The important step to activate the above middleware is to add the below label on the corresponding router and service. For instance, if you a a blog service and you defined a blog router for it, then you need to add the below table to the services
traefik.http.routers.blog.middlewares=blog-redirect
In addition, your route rule should look like the below rule to be able to handle both domains (or you define multiple routes per service)
- traefik.http.routers.blog.rule=Host(`example.com`) && Path(`/test`) || Host(`api.example.com``)
in this post, you can find more info about traffic and redirection

Google CDN Connection to CDN create nosuch Key Errors

i uploaded images to google storage bucket and i am no trying to set the CDN using the load balancer to work.
Storage Status :
Bucket Permissions : Storage Object Viewer - Reader assign to allUsers ,
Storage Legacy Bucket Reader assign To allUsers
File Status :
Share Public is set and there is a public link
Load Balancer:
Set to path /creatives/* on the host name
but i always get this msg:
<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
</Error>
what i notice is as soon as i build the path of /creatives/* there is another path build /* direct to the backend service of the auto scale group
am i missing here any settings?
So as i discovered Google CDN + Google http Load balancer works different from other CDN.
with a regular CDN you can direct the origin to you bucket HTTP address and work on the / structure.
for example :
Google CDN Bucket URL:
googleapi.storage.com/my-bucket
Folder structure:
/1/1.jpg
Normal CDN origin will be pointing to googleapi.storage.com/my-bucket
and you will get a new service endpoint for the CDN like:
my-bucket.fastly.cdonservice.com
and this call will work:
my-bucket.fastly.cdonservice.com/1/1.jpg
but on google cloud what you are setting up is a path that is connected to the CDN service that you created on the backend part.
So this is the big difference, lets assume that you created this path rule.
host: www.googlecdnnonexplainedfeautres.com
path: /images/*
service: yourbackendservice (connected to the bucket you want to cache)
so you might assume this should work:
www.googlecdnnonexplainedfeautres.com/images/1/1.jpg.
but NO ..
after digging the logs you will find a 404 on the bucket because google will go and search this path on the bucket:
googleapi.storage.com/my-bucket/images/1/1.jpg.
wait , where did the images came ? i thought its a hook. no google take this as a static website root ( the thing you can check on and off on S3) so here its mandatory.
so how this should work ?
modify the folder structure to be like this :
Google CDN Bucket URL:
googleapi.storage.com/my-bucket
Folder structure:
images/1/1.jpg
and now you are good.
This link should work now :
www.googlecdnnonexplainedfeautres.com/images/1/1.jpg.
so before you commit a bucket to be used as CDN source for google just add another top folder that match with the path you set on the LB.
and of course .. permissions , allUsers , read and etc..
EnjoY!
You can use URL Rewrites to solve this problem.
This may not have existed back in 2017 but there's an option at least as of 2021.
Explanation:
The lb's default behavior is to pass the entire path after the host to Cloud Storage. This may seem incorrect, but it's a sane default (How is the load balancer supposed to know what part of the path you want to include or exclude?).
I was facing the same issue.
I connected mydomain.com/static/* to my cloud storage bucket static-assets.
Upon visiting mydomain.com/static/static-asset.jpg the load balancer would request cloud storage for an object with key static-assets/**static**/static-asset.jpg.
Since the object's actual key is static-assets/static-asset.jpg, this would return a NoSuchKey response.
The fix was the rewrite the path prefix of /static to /.
One way to configure this is through the Cloud Console Load Balancer UI--we can add an advanced path rule to rewrite the prefix.
Please note:
Important: The rewrite is prepended to the path as is. Full path
rewrites are not supported. HTTP(S) Load Balancing only implements
path prefix rewrites. For example, you can rewrite:
host.name/path1/resource1 to host.name/path2/resource1. You cannot
rewrite host.name/path1/resource1 to host.name/path1/resource2.
Read about URL Rewrites here.

NGINX: subfolder to subdomain redirection doesn't work

yesterday i switched my sites to a new server. now i have a problem, because one domain i now run as a subdomain, was previously accessed as a subfolder and a few sites, which I have no access to, are still using that domain.com/subfolder/?some=parameters
so, long story short:
i need to update my nginx config file, to redirect my users from domain.com/subfolder/?some=parameters to subfolder.domain.com/?some=parameters
i searched for a solution for that problem yesterday, but couldn't fix the problem.
currently i have this in my conf file:
location /subfolder/ {
rewrite ^/subfolder(/.*)$ http://subfolder.domain.com$1 permanent;
}
which obviously redirects all requests from domain.com/subfolder/?some=parameters to subfolder.domain.com/?some=parameters, but requests to domain.com/subfolder/styles.css aren't redirected.
I think this is due to a conflicting location directive for specific static file extensions in your nginx config. I was able to get your rule to work by making it use a regular expression which influences the priority.
location ~ /subfolder/.* {
rewrite ^/subfolder(/.*)$ http://subfolder.domain.com$1 permanent;
}
See the details about the location directive, especially the rules and examples there about precedence.

URL Mapping based on Resource resolver in AEM

We have the following website structure:
content
mysite
en
home
testlevel1page
testlevel2page
Now the requirement is to map:
http://www.mysite.com/ --> /content/mysite/en/home.html
http://www.mysite.com/testlevel1page/ --> /content/mysite/en/home/testlevel1page.html
http://www.mysite.com/testlevel1page/testlevel2page/ --> /content/mysite/en/home/testlevel1page/testlevel2page.html
How can we achieve this through resource resolver?
Under the /etc/map/http directory, add a node "www.mysite.com" and give this a sling:internalRedirect property of /content/mysite/en/home.
As per the Sling documentation, this will "prefix the URI paths of the requests sent to this domain with the string" — i.e. in this case, appending "/content/my/en/home" after the domain name for any incoming requests to "www.mysite.com".
Optionally, if you place this under /etc/map.publish/http, this will only be applied to instances with a Sling run mode set to publish.
(As the rule is under a node called 'http', this won't be applied to secure requests. If you need to cater for 'https' too, you could copy the http node, or preferrably create a regex — this isn't as common a use case, but more info on the docs linked above.)