0

I am locally developing a website via MAMP and rather than messing with the changing all of my links and etc later on I opened up etc/hosts and added this line 127.0.0.1 localhost mysite.com so that my site thinks it has the mysite.com domain name, this works great. However I can't access a part of my site within a subdomain etc sub.mysite.com routes to localhost. Is there any way to route localhost to mysite.com yet still keep sub.mysite.com accessible?

UPDATE: I just found out that my subdomain is redirecting to my domain. I'm gonna guess that it is virtually impossible to prevent localhost from routing to some specific directory ex. mysite.com/example/.

ThomasReggi
  • 601
  • 2
  • 9
  • 24

2 Answers2

0

In windows, I think if "domain.com" is mapped to localhost, it is independent from sub.domain.com. You need to specify every single subdomain in the hosts file for it to work.

U4iK_HaZe
  • 631
  • 5
  • 13
0

I just got done figuring out what the problem was. If you look into your private/var/log/apache2/error_log (or whatever your error log file may be) you'll notice that there's an error that says VirtualHost overlap on port XXXX.

To get away without overlapping (which will default to the first VirtualHost) specify a NameVirtualHost in your httpd.conf like this:

NameVirtualHost *:80

<VirtualHost *:80>
  DocumentRoot "/Users/Thomas/Sites/mysite"
  ServerName mysite.com
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot "/Users/Thomas/Sites/subsite"
  ServerName sub.mysite.com
</VirtualHost>

You may have already figured out how to do this, but I had a difficult time trying to find the answer myself so I might as well make it easier to find for other people.

Andrew
  • 101
  • 1