Score:1

ErrorDocs | VirtualHost | Apache 2.2.x

pl flag

So, I'm having a challenge trying to get my virtual hosts (in the example, called bozo) to 'point' at the right error documents for 401, 403,... errors. I am trying the following construct, but it doesn't seem to work:

 <VirtualHost <ip.address.here>
  ServerAdmin [email protected]
  DocumentRoot /home/www/htdocs/virtual/bozo
  ServerName www.bozoclown.com
  ErrorLog logs/bozo_error_log

  ErrorDocument 401 errors/401.html
  ErrorDocument 404 errors/404.html
  ErrorDocument 403 errors/403.html
 </VirtualHost>

The custom error files 401.html, 403.html and so on are in the errors subdirectory, which is off the document root. If I point a browser at www.bozoclown.com/errors/403.html, the 403.html files comes up (so it, and the other error files, are there, and accessible). But, when I intentionally generate a 403 error accessing the virtual site, I'm not being sent to the custom 403 page. Instead, I'm getting the following error:

You don't have permission to access / on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

So, I try adding the following in the virtual host declaration:

<Directory "/home/www/htdocs/virtual/bozo/errors">
  Order allow,deny
  Allow from all
</Directory>

But that doesn't work.

Suggestions? Pointers to the obvious correction I need to make?

Thanks in advance.

Score:0
by flag

You gonna need to modify your configuration file a little, you need an Alias directive to map the /errors URL path, update the ErrorDocument to the URL path instead of the file path.

Here is the final file, after restarting the Apache server it should work

<VirtualHost <ip.address.here>>
  ServerAdmin [email protected]
  DocumentRoot /home/www/htdocs/virtual/bozo
  ServerName www.bozoclown.com
  ErrorLog logs/bozo_error_log

  Alias /errors "/home/www/htdocs/virtual/bozo/errors"
  <Directory "/home/www/htdocs/virtual/bozo/errors">
    Options -Indexes
    Order allow,deny
    Allow from all
  </Directory>

  ErrorDocument 401 /errors/401.html
  ErrorDocument 404 /errors/404.html
  ErrorDocument 403 /errors/403.html
</VirtualHost>
Johnny Canuck avatar
pl flag
Many thanks. I'll give that a try.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.