1

I am currently trying to develop a small Apache module which needs to retrieve the request's document root (as defined in the server configuration).

I had a look at httpd.h to see if I could find this information somewhere in the data structures (request_rec, server_rec) but I couldn't find anything like it.

Is it possible to retrieve the request's document root from an Apache module?

John WH Smith
  • 2,743
  • 1
  • 21
  • 31
  • 1
    What you are looking for is in [http_core.h](http://svn.apache.org/repos/asf/httpd/httpd/trunk/include/http_core.h): `AP_DECLARE(const char *) ap_document_root(request_rec *r);` – kums Oct 23 '14 at 10:26
  • BTW, there's a warning on its usage; `"Modules shouldn't be worried about the document root. If you need to call this function, then you should ask yourself "why". Modules should be more concerned with r->uri and r->filename."` [source](https://www.mail-archive.com/dev@httpd.apache.org/msg06776.html) – kums Oct 23 '14 at 10:31
  • @kums Actually, my case is a little specific: I want the module to create the document root when it does not exist. It does not really "handle" the request, it prepares it, at least for some hosts. Please post your comment as an answer so I can accept it ;) – John WH Smith Oct 23 '14 at 10:59

1 Answers1

1

What you are looking for is in http_core.h:

AP_DECLARE(const char *) ap_document_root(request_rec *r);

BTW, there's a warning on its usage:

"Modules shouldn't be worried about the document root. If you need to call this function, then you should ask yourself "why". Modules should be more concerned with r->uri and r->filename." [source]

kums
  • 2,661
  • 2
  • 13
  • 16