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).

2
  • nginx can do this very easily with return, i.e.: return 200 "Hi there"; but I can't find anything relevant for Apache. Commented Feb 25, 2019 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. Commented Feb 25, 2019 at 20:32

1 Answer 1

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

1
  • 1
    Thank you for your suggestion. It is an interesting workaround, but I'd rather have a success code returned... Upvoted anyway. Commented Feb 25, 2019 at 20:34

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.