简体   繁体   中英

Apache: Dynamically set the DocumentRoot inside a VirtualHost section?

In an Apache VirtualHost section, is it possible to dynamically assign a DocumentRoot based on hostname instead of having one VirtualHost section for each hostname?

I have many hostnames that all share the same wildcard certificate and many other parameters. So it would be much better to have them all inside one VirtualHost section and set the DocumentRoot bases on the hostname.

The module mod_vhost_alias offers this functionality. Instead of DocumentRoot , you would define VirtualDocumentRoot where you can embed variables from the request.

Simplest example from linked documentation:

 UseCanonicalName Off VirtualDocumentRoot "/usr/local/apache/vhosts/%0"

A request for http://www.example.com/directory/file.html will be satisfied by the file /usr/local/apache/vhosts/www.example.com/directory/file.html .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM