Setting up Virtual Hosts on Mac with different subdirectories
-
19-06-2021 - |
سؤال
I have problems setting up my local development environment on a mac.
What i have (added):
/private/etc/hosts:
127.0.0.1 dev.local
127.0.0.1 page1.dev.local
/Applications/MAMP/conf/apache/httpd.conf:
NameVirtualHost *
<VirtualHost dev.local:8888>
ServerName dev.local
DocumentRoot /Users/user1/Sites/
<Directory /Users/user1/Sites/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost page1.dev.local:8888>
ServerName page1.dev.local
DocumentRoot /Users/user1/Sites/page1/
<Directory /Users/user1/Sites/page1/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Basically I would like to have a "root" accessible via http://dev.local and physically at /Users/user1/Sites
The first project (page1) accessible via http://page1.dev.local and located at /Users/user1/Sites/page1
The next projects follow the same logic.
When I open http://dev.local I see the correct page but with http://page1.dev.local I get the same page.
I always restart Apache of course!
المحلول
I found a solution which works: I have to insert a ServerAlias
and add an asterix after VirtualHost
NameVirtualHost *
<VirtualHost *:8888>
ServerName dev.local
ServerAlias dev.local
DocumentRoot /Users/user1/Sites/
<Directory /Users/user1/Sites/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:8888>
ServerName page1.dev.local
ServerAlias page1.dev.local
DocumentRoot /Users/user1/Sites/page1/
<Directory /Users/user1/Sites/page1/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
لا تنتمي إلى StackOverflow