Mobile app version of vmapp.org
Login or Join
XinRu657

: Apache virtual hosts configuration for MAMP results in new sites going to the same folder I have MAMP installed in my mac. Why is it that every time I create a new site, they all go to

@XinRu657

Posted in: #Apache #Htaccess #Mamp #Virtualhost

I have MAMP installed in my mac. Why is it that every time I create a new site, they all go to the same folder? Here is my /etc/hosts file:

127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 localhost.funstuff
127.0.0.1 localhost.mysite
127.0.0.1 localhost.oldmysite


This is my httpd-vhosts.conf

NameVirtualHost *:8888


############ FUN STUFF PAGE##############
<VirtualHost localhost.funstuff:8888>
ServerName localhost.funstuff
DocumentRoot "/Applications/MAMP/htdocs/funstuff"
ServerAlias localhost.funstuff
</VirtualHost>



<VirtualHost localhost.mysite:8888>
ServerName localhost.mysite
DocumentRoot "/Applications/MAMP/htdocs/mysite"
ServerAlias localhost.mysite
</VirtualHost>

#### oldmysite ####
<VirtualHost localhost.oldmysite:8888>
ServerName localhost.oldmysite
DocumentRoot "/Applications/MAMP/htdocs/oldmysite/sites/oldmysite"
ServerAlias localhost.oldmysite
</VirtualHost>


I've restarted the MAMP server and when I type: localhost.funstuff:8888/, localhost.oldmysite:8888 or localhost.mysite:8888, it all goes to the fun stuff folder.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @XinRu657

1 Comments

Sorted by latest first Latest Oldest Best

 

@Kimberly868

Apache doesn't recommend using domains in the <VirtualHost> declaration, I have found from experience that you will have far less trouble using an asterisk here (*) and just let the domain be matched against the ServerName value.

Also, the first virtual host site behaves as a default for whenever the name does not exactly match one of the defined virtual hosts. Therefore I would recommend if you do not want the fun stuff page to be your default site, try adding a new default VirtualHost and corresponding blank page website to your httpd.conf file.

NameVirtualHost *:8888

# Default Virtual Host Site - Blank
<VirtualHost *.8888>
ServerName localhost
DocumentRoot /Applications/MAMP/htdocs/default
</VirtualHost>

# Fun Stuff Page
<VirtualHost *:8888>
ServerName localhost.funstuff
ServerAlias localhost.funstuff DocumentRoot /Applications/MAMP/htdocs/funstuff
</VirtualHost>

# My Site
<VirtualHost *:8888>
ServerName localhost.mysite
ServerAlias localhost.mysite DocumentRoot /Applications/MAMP/htdocs/mysite
</VirtualHost>

# My Old Site
<VirtualHost *:8888>
ServerName localhost.oldmysite
ServerAlias localhost.oldmysite DocumentRoot /Applications/MAMP/htdocs/oldmysite/sites/oldmysite
</VirtualHost>

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme