0

I only have a fuzzy idea of the correct terminology to use in this question so please feel free to help me by clarifying it.

I have a vhost setup. The idea is that I want a wildcard to route all requests for root.TERM.lh to a /TERM/ document root.

The setup below recognises the domains fine and routes them accordingly, but it doesn't translate the %1 in the document root to TERM. For eg the Apache error log tells me that for a request to root.mywebsite.lh it's attempting to route to /Users/hollsk/Dev/websites/%1, so it's interpreting it as a literal string.

Is my syntax incorrect, or am I missing some module?

NameVirtualHost *
<VirtualHost *>
    ServerName root.%1.lh
    ServerAlias root.%1.lh
    DocumentRoot /Users/hollsk/Dev/websites/%1/
</VirtualHost>
  • Take a look at mod_macro for Apache, if I understand your question correctly, it'll allow you to do what you want. – Mxx Feb 16 '13 at 20:53
3

This style of configuration requires using an add-on module, not the core virtual hosting directives.

See VirtualDocumentRoot here: http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html

  • Ta. The module was already enabled, and the problem was my syntax. Upvoting as the answer would help somebody else without the module switched on, though. – hollsk Mar 2 '13 at 12:17
0

My syntax was subtly incorrect.

NameVirtualHost *
<VirtualHost *>
    ServerName root.%2.lh
    ServerAlias root.%2.lh
    DocumentRoot /Users/hollsk/Dev/websites/%2/
</VirtualHost>

Note the %2 instead of %1 - still not sure why %1 was being intepreted literally (instead of as the string root, which is what I'd expect), but changing to the correct handle fixed the problem in any case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.