I want to make apache to always open up a signle page for 404 errors from all subdomains.
The problem is that my subdomains are located in subfolders in public_html, and thus have a different root path.
For example the main domain this works quite well:
ErrorDocument 404 /Error/404.html
The Error folder and the main domain are located in public_html respectively.
However for the forum subdomain, located in public_html/forum/ the above root path does not, and it actually looks for public_html/forum/Error/404.html which doesn’t exist.
I tried to rewrite rule for the forum folder, but it didn’t work out either:
ErrorDocument 404 /../Error/404.html
Seems, it cannot go below the root folder for some reason.
Any ideas how can I refer to the same page from the main and the subdomain alike, without triggering redirects? (eg: http://mysite/Error/404.html would accomplish this, but would also change the url address of the page which I don’t want)
Because being able to traverse above the document root is a very, very serious security risk. If your webserver gets compromised, people would be able to serve all kinds of files anywhere on your entire server.
If you have access to server config you can setup aliases for the
/Errorfolder. For example, in your forum subdomain’s vhost config, you can add:This way, when you go to
http://forum.yourdomain.com/Error/404.htmlyou’d actually be looking athttp://main.yourdomain.com/Error/404.html. Then you can just use:like normal in your forum subdomain.
But if you don’t have access to your server/vhost config, you’ll need to use mod_proxy and mod_rewrite. So in the htaccess file in
public_html/forum/, add these to the top: