Using CNAME / hostfile to redirect from one domain to a completely different domain

User makocisa asked this question and I have the same requirement:

Continuing the discussion from Use DNS to force youtube into restricted mode - and Pi-Hole:

I'd like to redirect
twitter.com/[postid]
to
nitter.net/[postid]

(Same technique would apply with youtube/ invidious)

I've tried configuring the CNAME records as described in that thread (and adding the return to the hostfile), and it seems to work with ping just fine. Unfortunately, because of SSL, actually browsing doesn't work. Browsers flag the SSL difference and don't load the page.

Which is fair, I'm basically doing a MITM attack.

Is there any way to do this on a Pihole at the network level? Or is this something that, for network reasons, would have to happen with a local browser extension or something?

No, not by DNS means alone.

You may be able to use URL redirection through a local web server.
You'd still need a local DNS record for resolving twitter.com to the local IP of your web server, which in turn would define your ultimate HTTP/S redirection targets. You still wouldn't get rid of certificate warnings that way.

You may be able to get rid of the certificate errors by adding your certificate as ultimate trusted to the devices that try to visit the pages (if at all possible). I see no other way. You hit the nail on its head with

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