Make a website to forbid access to anyone except another domain

Hi.
I have two websites, example1.com and example2.com.

I want to make it the way that anyone who tries to access example2.com get a 403 forbidden error. Except when it’s example1.com that tries to access example2.com, this way I want example2.com to redirect to another URL.

Something like:

All IPs > 403 forbidden
example1.com exclusively > some other url

I know it’s possible to do with Apache natively by editing .htaccess this way:

Require forward-dns example1.com
RewriteEngine on
RewriteRule ^(.*)$ https://other\.url\.com/$1 [L,R=302]

But with CyberPanel, the first part (require forward-dns) doesn’t work. Everyone who visits example2.com gets redirected to some other url, not only example1.com.

What would be my best option?

For the context, example2.com is not intended for any unauthorized access, it’s a tunnel (with a checkpoint) to media content located on a CDN network I want to mask with example2.com. example1.com tries to access example2.com/picture.jpg, gets redirected to someotherurl.com/picture.jpg, then shows picture.jpg to the viewer. Everyone else see someotherurl.com/picture.jpg as example2.com/picture.jpg and get 403 if they try to access it.