2

Using apache 2.4 on Linux, with several virtual servers, each virtual server with its own DocumentRoot, I would like for the apache main server ErrorDocument local redirect to execute a single perl script relevant to the apache main DocumentRoot, and not a perl script under each virtual server.

What happens is that the virtual server's document root is used to construct the file system path, instead of the main server's document root.

Is there some way that I can configure the apache server to only use a single local redirect script, instead of (apparently) having to have an (identical) script in each virtual server's DocumentRoot?

keith20mm
  • 31
  • 1
  • 2

2 Answers2

3

You can set a single global error document by placing the following directives in the global (Server) context (i.e. not inside any <VirtualHost> block). It will then work for all your virtual hosts. This shows you a static HTML file, but it can easily be modified to be a perl script instead

Alias /error-404.html /path/to/my/errors/error-404.html
ErrorDocument 404 /error-404.html

<Directory "/path/to/my/errors">
  require all granted
</Directory>
Unbeliever
  • 2,336
  • 1
  • 10
  • 19
0

You can set ErrorDocument as an external resource e.g.

ErrorDocument 500 http://error.example.com/server_error.html

So you could just reference the script on your main vhost.

Believe it or not this is documented in the documentation for ErrorLog.

user9517
  • 115,471
  • 20
  • 215
  • 297
  • My apology.. I should have also stated that I need the environment variables to be passed to the script. The external URL doesn't pass the variables, according to the documentation. – keith20mm Aug 24 '16 at 13:24