How can I redirect all https://www.A.net/Page.html requests for some page Page.html to the corresponding page on another domain https://www.B.net/Page.html via the https://www.A.net/404.html? Github/Gitlab Pages redirect all Page-not-found errors to the latter. Is it possible to somehow retrieve the original requested page and use this in a Javascript function to modify the redirection URL?
I currently use something like the following HTML code for a many-to-one redirection, but I rather need a one-to-one redirection (i.e. not always to the same https://www.B.net/404.html).
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta http-equiv="refresh" content="0; URL=https://www.B.net/404.html">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<meta name="viewport" content="width=device-width; initial-scale=1.0"/>
</head>
<body>
You are being redirected to https://www.B.net/404.html <a href="https://www.B.net/404.html">https://www.B.net/404.html</a>
</body>
</html>
Current situation (many-to-one):
www.A.net/Page1.html -> www.A.net/404.html -> www.B.net/404.html
www.A.net/Page2.html -> www.A.net/404.html -> www.B.net/404.html
Desired situation (one-to-one):
www.A.net/Page1.html -> www.A.net/404.html -> www.B.net/Page1.html
www.A.net/Page2.html -> www.A.net/404.html -> www.B.net/Page2.html
Note that I host static websites at Github/Gitlab.
Specific context: I want to redirect my Gitlab and Bitbucket Pages to my Github Pages.