I'm attempting to setup a local development server where I can simply access any project within a directory E:\\development\\projects\\
and have apache automatically redirect me to the correct subdomain.
However when attempting to redirect to a sub-subdomain ( backend.project01.dev01
), I simply get a "server unreachable" message.
See my httpd-vhosts.conf for more info:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName dev01
ServerAlias www.dev01
DocumentRoot "E:\development\projects"
ErrorLog "logs\errors.log"
<directory "E:\development\projects">
</directory>
</VirtualHost>
<VirtualHost *:80>
ServerName dev01
ServerAlias *.dev01
VirtualDocumentRoot "E:\development\projects\%1"
ErrorLog "logs\errors.log"
<directory "E:\development\projects\%1">
</directory>
</VirtualHost>
<VirtualHost *:80>
ServerName dev01
ServerAlias *.*.dev01
VirtualDocumentRoot "E:\development\projects\%2"
ErrorLog "logs\errors.log"
<directory "E:\development\projects\%2">
</directory>
</VirtualHost>
In a nutshell:
This work: project01.dev01/
This doesn't work: backend.project01.dev01/
So I've found a solution. To match sub-subdomains, you have to match the deepest
level first.
Ie: match deepest.sub.domain
before sub.domain
The answer in this example is:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName dev01
DocumentRoot "E:\development\projects"
ErrorLog "logs\errors.log"
<directory "E:\development\projects">
</directory>
</VirtualHost>
## moved this up
<VirtualHost *:80>
ServerName dev01
ServerAlias *.*.dev01
VirtualDocumentRoot "E:\development\projects\%2"
ErrorLog "logs\errors.log"
<directory "E:\development\projects\%2">
</directory>
</VirtualHost>
## moved this down
<VirtualHost *:80>
ServerName dev01
ServerAlias *.dev01
VirtualDocumentRoot "E:\development\projects\%1"
ErrorLog "logs\errors.log"
<directory "E:\development\projects\%1">
</directory>
</VirtualHost>
In this example apache will always first attempt to match the *.*.dev01
and if it fails, attempt to match *.dev01
.
Hopefully this will help others in the future.
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.