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.
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.
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:
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With