Subdomain redirect

Hi all, quite new to Cloudflare, am competent in adding Basic records and entries, however I have something which I’m unsure how to do.
There is a new email Security protocol called MTA-STS. Basically it’s a couple of TXT records, which is the easy bit. The hard bit is the routing of a URL to a txt file. I believe this can be done due to some testimonials on the NCSC site.
So…

I have a domain: maindomain.com
I have a txt file: otherdomain.com/files/mta-sts.txt

I need the following URL to resolve to the txt file:

mta-sts.maindomain.com/.well-known/mta-sts.txt

How do I use dns records and/or page rules? I followed a guide earlier to set up a page rule which basically redirected the url to the txt file, but I think I need to specify the subdomain somewhere. Is it as easy as directing mta-sts. to maindomian.com?

Thanks in advance.

Normally, you’d set up your host to include this subdomain, then Cloudflare can proxy it. I don’t think a redirect will work for mta-sts.

What I do is create a Worker for this that contains my .txt data:

async function handleRequest(request) {
  const init = {
    headers: {
      'content-type': 'text/plain;charset=UTF-8',
    },
  }
  return new Response(someHTML, init)
}
addEventListener('fetch', event => {
  return event.respondWith(handleRequest(event.request))
})
const someHTML = `version: STSv1
mode: enforce
mx: mx1.example.com
mx: mx2.example.com
max_age: 86400
`

And then create a Workers Route that matches that hostname, also making sure I have that hostname in DNS as a :orange: Proxied record. An “A” record with an IP address of 192.0.2.1

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.