Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sites-available (apache) and httpd.conf for WAMP - making XXXXX.domain.com automatically direct

I currently have this in my httpd.conf file in WAMP:

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
    ServerAlias *.dev.co.uk
    UseCanonicalName Off
    VirtualDocumentRoot D:/wamp/www/%1/httpdocs
</VirtualHost>

I created a directory "foo.bar" and then tried http://foo.bar.dev.co.uk and I get this:

Not Found

The requested URL / was not found on this server.

I want to get this setup working on my local apache server as well as my wamp server (I think the syntax is slightly different). If I need to give more info then leave a comment and I'll update.

like image 687
udjamaflip Avatar asked Dec 20 '25 21:12

udjamaflip


1 Answers

I've never used VirtualDocumentRoot, but seeing that you're not getting any responses I'll give it a go.

According to the docs on Directory Name Interpolation, it would seem like your problem lies in your use of %1 which will match only "foo" for http://foo.bar.dev.co.uk.

To match "foo.bar", try:

VirtualDocumentRoot D:/wamp/www/%1.0.%2.0/httpdocs

%1 matches "foo" while %2 matches "bar". The addition .0 appended to each format is to allow us to include the dot in between foo and bar (since . is also a used as an operator to extract a substring of the matched words).

If that doesn't work, do check the logs to see which directory Apache is actually looking for. That may provide hints as to what has gone wrong.

Update

In response to:

"This does make foo.bar.dev.co.uk however, unfortunately it stops foo.dev.co.uk from working, any ideas?"

Using directory name interpolation to match aliases with indeterminate numbers of subdomains is tricky.

The most straight forward approach would be to simply use %0 and have the directories named after the full domain name.

VirtualDocumentRoot D:/wamp/www/%0/httpdocs

This will match with directories D:/wamp/www/foo.bar.dev.co.uk/httpdocs and D:/wamp/www/foo.dev.co.uk/httpdocs.

If you have a limited subset of possible domains, a more specific solution can be crafted. For example, if you have:

  • "foo.dev.co.uk"
  • "bar.dev.co.uk"
  • "foo.bar.dev.co.uk"
  • .. and more domains in the form "X.Y.dev.co.uk"

then you can handle "foo" and "bar" a preceding VirtualHost block before handling the other domains.

<VirtualHost 127.0.0.1>
    ServerAlias foo.dev.co.uk 
    ServerAlias bar.dev.co.uk
    UseCanonicalName Off
    VirtualDocumentRoot D:/wamp/www/%1/httpdocs
</VirtualHost>

<VirtualHost 127.0.0.1>
    ServerAlias *.dev.co.uk
    UseCanonicalName Off
    VirtualDocumentRoot D:/wamp/www/%1.0.%2.0/httpdocs
</VirtualHost>
like image 141
Shawn Chin Avatar answered Dec 23 '25 09:12

Shawn Chin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!