Snert . Com mod_vd/2.0
      from   Snert . Com
 

- Welcome - Software -

Description

This Apache 2.0 module is similar to mod_vhost_alias, in that it maps the request host name and URI to the file system. For example http://www.john.smith.domain.name/ might be mapped to /home/smith/john/public_html.

While the same can be achieved with mod_vhost_alias or mod_rewrite, the goal of this module is to be faster than the others modules performing similar mappings of a request to file system, by using a more rigid translation, avoiding regular expressions, and avoiding the need for any complex substitutions. On a very active server, regular expressions and complex string manipulation can impact server performance.

This module can be used in combination with static virtual hosts and other dynamic virtual host modules like mod_vhost_alias, depending on the module execution order specified in the httpd.conf.

Configuration

VdChopPrefix number
Context: global, <VirtualHost>

Remove the leading number of domain levels from the request hostname. The default is zero (0).

VdChopSuffix number
Context: global, <VirtualHost>

Remove the trailing number of domain levels from the request hostname. The default is zero (0).

VdEnable flag
Context: global, <VirtualHost>

Turn the module on or off.

VdPathPrefix directory
Context: global, <VirtualHost>

This is an absolute or server root relative directory path, to which will be appended the translated hostname, suffix, and URI. The default is the global or static virtual host document root.

VdPathSuffix directory
Context: global, <VirtualHost>

This is a path suffix that will be appended to the prefix and the translated hostname. Once the suffix is appended, the requested URI is then appended. The default is the empty string, "".

The Translation

When the module is enabled, the virtual host to file path translation that is performed is as follows:

  1. To begin, assume the following example configuration:

    VdChopPrefix 1
    VdChopSuffix 2
    VdPathPrefix /home
    VdPathSuffix /public_html
    
  2. Now if the requested URL looked like:

    http://www.anthony.christopher.howe.member.com/image/mypicture.png
    

    then the HTTP request would resemble something like this:

    GET /images/mypicture.png HTTP/1.0
    Host: www.anthony.christopher.howe.member.com:80
    
  3. The VdChopPrefix and VdChopSuffix are first applied to the Host: header provided by the request to remove leading and trailing domain segments and would result in this:

    anthony.christopher.howe
  4. Next, the order of the remaining domain segments is reversed and the dots replaced by slashes (/), leaving this:

    howe/christopher/anthony
  5. To complete the file path, the module concatenates the VdPathPrefix, the translated Host: header, the VdPathSuffix, and the requested URI. The resulting file path would be:

    /home/howe/christopher/anthony/public_html/images/mypicture.png
  6. Finally, the module verifies that the file path actually exists. If it does not exist, the module discards the file path and passes the the request onto other Apache modules to treat. Otherwise, the file path is good and the translation is complete.

Installation

  1. Download either:

  2. Before building mod_vd, please review and alter the configuration settings found at the top of Makefile.dso.

    To build as a shared library for Apache 2.0:

    cd (path to)/mod_vd-2.0
    make -f Makefile.dso install
    
  3. To build as a static module into Apache 2.0:

    cd (path to)/apache_2.0.44
    mkdir -p modules/com/snert
    mv (path to)/mod_vd-2.0 modules/com/snert/vd
    ./buildconf			# This step can take a long time.
    ./configure \
        --enable-vd=static \
        ... (your other configuration options) ...
    make install
    
  4. To test, add the following example configuration to httpd.conf, which could be used as an alternative to http://www.host.domain/~user/:

    #
    # Allow URLS of the form http://user.domain.tld/ as an alternative
    # to http://www.domain.tld/~user/ The former will require a DNS entry,
    # but is prettier.
    #
    <IfModule mod_vd.c>
      VdEnable on
      VdChopSuffix 2
      VdPathPrefix /home
      VdPathSuffix /public_html
    </IfModule>
    
  5. Restart the web server:

    apachectl restart

Notes

  • mod_vd is short for mod_virtual_domain and any other implied meaning is purely unintentional.


- Welcome - Software -

jack-in-the-boxes since 9 January 2003