Home Non existing subdomain error handling using php and .htaccess

# Non existing subdomain error handling using php and .htaccess

user41065
1#
user41065 Published in September 19, 2018, 3:18 am

In order to track errorhandling I set the errordocuments in .htaccess to a script like so:

ErrorDocument 400 /catch
ErrorDocument 401 /catch
ErrorDocument 403 /catch
ErrorDocument 404 /catch
ErrorDocument 405 /catch
ErrorDocument 408 /catch
ErrorDocument 500 /catch
ErrorDocument 502 /catch
ErrorDocument 504 /catch


In the catch script I take the url that generated the error and write to db, before redirecting to /error. On the website there are numerous subdomains, each with their own catch and error page. However, I need all non existing subdomains to redirect to the catch of the main domain, without changing the url (nonexistingsubdomain.example.org becomes https://www.example.org/nonexistingsubdomain which should be catched by the catch script in which:

$url= (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";