0

I would like my Apache VirtualHost to respond with the same content, no matter the URL requested. I know it is possible with an additional file containing the static response (https://askubuntu.com/a/485017/600828).

However, my response content is very short and simple, and I would like to know if it is possible to include it in the Apache site config file directly (so that I have only one file to deploy & maintain instead of 2).

  • nginx can do this very easily with [`return`](https://nginx.org/r/return), i.e.: `return 200 "Hi there";` but I can't find anything relevant for Apache. – Michael Hampton Feb 25 '19 at 17:18
  • Indeed @MichaelHampton. The reason I want to do it with Apache is that I am using Apache as a reverse proxy to multiple apps, so if I use anything else it would be behind Apache anyway. – Nathan.Eilisha Shiraini Feb 25 '19 at 20:32

1 Answers1

1

You can define the text for 404 and other error conditions in the main Apache httpd.conf with the ErrorDocument directive https://httpd.apache.org/docs/2.4/custom-error.html

When your documentRoot is empty and you don’t permit directory listings requests for your bare domain should trigger an 403 error and all other URLs will trigger a 404 so with the following (ugly) solution you get what you want

<VirtualHost *:80>
   ServerName www.example.com
   DocumentRoot /path/to/empty/dir 
   ErrorDocument 404 "some text"
   ErrorDocument 403 "some text"
   .,.
 </VirtualHost > 

Please note that your some text needs to be long enough to prevent certain browsers from displaying their own friendly error messages

Illya Moskvin
  • 293
  • 2
  • 6
HBruijn
  • 77,029
  • 24
  • 135
  • 201