使用.htaccess来获取同一服务器上另一个域上的错误页面

I made a custom php error page with the following code:

<?php 
$status = $_SERVER['REDIRECT_STATUS'];
$codes = array(
       400 => array('400 Bad Request', 'The request could not be understood by the server due to malformed syntax.'),
       401 => array('401 Unauthorized', 'The request requires user authentication.'),
       403 => array('403 Forbidden', 'The server has refused to fulfill your request.'),
       404 => array('404 Not Found', 'The document/file requested was not found on this server.'),
       405 => array('405 Method Not Allowed', 'The method specified in the Request-Line is not allowed for the specified resource.'),
       408 => array('408 Request Timeout', 'Your browser failed to send a request in the time allowed by the server.'),
       500 => array('500 Internal Server Error', 'The request was unsuccessful due to an unexpected condition encountered by the server.'),
       501 => array('501 Not Implemented', 'The server does not support the functionality required to fulfill the request.'),
       502 => array('502 Bad Gateway', 'The server received an invalid response from the upstream server while trying to fulfill the request.'),
       504 => array('504 Gateway Timeout', 'The upstream server failed to send a request in the time allowed by the server.'),
);

$title = $codes[$status][0];
$message = $codes[$status][1];
if ($title == false || strlen($status) != 3) {
       $message = 'Please supply a valid status code.';
}
    echo $title; ?>

I have around 50 domains on my server that I want to use these custom error pages but when I edit the .htaccess files to:

ErrorDocument 404 /../www/error.php

or

ErrorDocument 404 /../public_html/error.php

I get no love, and when I just type in main domain like this

ErrorDocument 404 https://example.com/error.php

it just redirects.

How can this be done? Thanks.