Using constant variables in apache configuration

apache-2.2configurationhttpd.conf

<VirtualHost *:80>
SetEnv SITENAME testing
ServerName www.test.com

# Location of files
DocumentRoot "/www/${SITENAME}/site"
Alias /data "/www/data/${SITENAME}"
Alias /base "/www/${SITENAME}/base/site"

# Logging
ErrorLog "/var/log/httpd/${SITENAME}-error.log"
CustomLog "/var/log/httpd/${SITENAME}-access.log" combined
</VirtualHost>
  • Starting apache2 …
    Warning: DocumentRoot [/www/${SITENAME}/site] does not exist

A further reading of the documentation provides a hint that SetEnv may not bind early enough to be used in paths and the suggested alternative SetEnvIf is based on the request properties as well.

I've also seen examples using mod_vhost_alias however that does not seem to handle anything but the DocumentRoot and even then it's required to use components of the server name which is not what I want.

What I want is pure variable substitution available when the config is read and usable in any string (like a #DEFINE in C). My Apache version is 2.2. Can it be done?

UPDATE: I found a Define directive in the documentation but it doesn't work (looks like it's new to 2.3). I guess the question now is wether there's a module that backports this or equivalent functionality to 2.2?

Best Answer

This has been asked before. The link is here:

Using variables in Apache config files to reduce duplication?

Related Topic