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 thi开发者_如何学运维nk 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.
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>
Some comments that might support :
1) to resolve your localhost ip
You have to get your browser able to find what's on 127.0.0.1. So, if not done, first edit the hosts file on your Windows OS machine C:\Windows\System32\drivers\etc\hosts :
127.0.0.1 foo.bar.dev.co.uk
Provided this is not possible to use wildcards in that host file. To do so, you shall install this.
2) port :
Make sure your server is listening to the http default port, eg do not forget to add this directive in your httpd.conf file (as I did not see it) :
Listen 80
3) Control :
As you're using the NameVirtualHost XXX.XXX.XXX.XXX directive, make sure the is exactly matching the NameVirtualHost directive. It looks like this is the case on your post.
4) Path :
That's maybe a stupid remark from my side, as a Linux user, but I thought Windows OS requires backslashes for the path, and not slashes. But I might be definitely wrong there and would not like to mislead anybody. But as "all the directives in this Directory Name Interpolation module interpolate a string into a pathname, I would check the result of The obtained interpolated string. Pls see next point.
5) Placeholders :
Make sure the module vhost alias is loaded into your wamp.
I would also recommend you to add a directive in your vhost sothat you can check in the logs what's the required interpolated URL, find what's wrong, and correct accordingly your apache setup :
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog logs/access_log common
6) Existing solution...
An existing problem has always existing solutions : See there
Once you'll have checked these points, I guess the solution would appear soon.
精彩评论