Paths In Server Side Includes
for Apache WebServers

Overview

From within HTML files you may execute various Server Side Includes such as #exec and #include which reference files on a relative or absolute path. This note attempts to clarify the root of the path used in each case, along with other non-obvious information.

Note that there may be several different  paths in the picture:

The #exec Command

#exec cgi="/path/cgifile" or #exec cgi="path/cgifile"

If the target file's path begins with a slash, it is taken relative to the DocumentRoot of the web site (as specified in httpd.conf).  Otherwise, the target file's path is taken relative to the path of the invoking HTML file.

The printed output of the cgifile must be a valid CGI result. In particular, it must begin with a valid "Content-type:" directive.

#exec cmd="path/file" or #exec cmd="/path/file"

If the target file's path begins with a slash, it is taken relative to ~/, that is, /usr/home/yourdomain. Otherwise, the target file's path is taken relative to the path of the invoking HTML file.

All of the printed output from within the shell script is included in the result of the HTML file. In particular, if the output contains a "Content-type:" directive, then that text is included directly in the HTML file's output (which is probably not what you want).

The #include Command

#include virtual="path/file" or #include virtual="/path/file"

If the target file's path begins with a slash, it is taken relative to the DocumentRoot of the web site (as specified in httpd.conf).  Otherwise, the target file's path is taken relative to the path of the invoking HTML file.

If the included file is to be executed as a CGI script, then the printed output must be a valid CGI result. In particular, it must begin with a valid "Content-type:" directive.

#include file="path/file"

The target file's path is always taken relative to the path of the invoking HTML file. It may not begin with a slash, and it may not contain ../.

If the included file is to be executed as a CGI script, then the printed output must be a valid CGI result. In particular, it must begin with a valid "Content-type:" directive.

Valid XHTML 1.0! Valid CSS!
GetNARS2000!
NARS2000
© 2006-2020
Get GPL v3!   Get Firefox!   Get Thunderbird!   Get LibreOffice!   I Support Science!
Comments or suggestions? Send them to .