Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hosts file and multiple sub-domains

For local testing (and learning), I wish to use x.com host name instead of localhost. I changed my Windows XP host file to this -

127.0.0.1       x.com

Now http://x.com/ works beautifully but http://www.x.com doesn't. :(

What changes should I make so that www.x.com, sub1.x.com, sub2.x.com etc.. all work on local. WordpressMU will lets users create sub-domains dynamically.

I am basically trying to setup WordpressMU locally. I'm using Apache/2.2.4, PHP/5.2.4, and MySQL5.

Please help!

like image 992
Arpit Tambi Avatar asked Jul 03 '09 07:07

Arpit Tambi


People also ask

Can you have multiple sub domains?

Each domain name can have up to 500 subdomains. You can also add multiple levels of subdomains, such as info.blog.yoursite.com. A subdomain can be up to 255 characters long, but if you have multiple levels in your subdomain, each level can only be 63 characters long.

Does host include subdomain?

According to RFC 1034, "a domain is a subdomain of another domain if it is contained within that domain". Based on that definition, a host cannot be a subdomain, only a domain can be a subdomain. A subdomain will also have a separate zone file with a SOA record (Start of Authority).

How do you add subdomains to ETC hosts?

Install a DNS forwarder using Homebrew. Create a configuration to map the wildcard subdomains to the same IP. Restart the service. Create /etc/resolver directory.

Can you host a subdomain on a different host?

Update A Record of Sub-domain and point it to another hosting: This one step is the most crucial part of hosting your sub-domain on another hosting account. You need to go to your domain registrar and add A record for your sub-domain to point it to your new server. I.P address will be of your new hosting sever I.P.


2 Answers

You can also put all the host names for an IP address on the same line:

127.0.0.1 x.com www.x.com sub1.x.com sub2.x.com

If you have a lot of sub-names, it would certainly be easier with a wildcard but unfortunately this is not supported with the hosts file.

Alternatively you could download the trial version of Simple DNS Plus which you can use to run a local DNS server on your XP machine (make sure to setup TCP/IP to use 127.0.0.1 for DNS). This allows you to setup wildcard entries like *.x.com.

like image 103
Jesper Avatar answered Sep 30 '22 08:09

Jesper


You can repeat the same IP address several times to redirect multiple host names. You have to list the full host names though -- you can't list domain names or wildcards and expect all hosts in that domain to redirect to the IP address.

127.0.0.1 x.com
127.0.0.1 www.x.com
127.0.0.1 sub1.x.com
127.0.0.1 sub2.x.com
like image 44
Oren Trutner Avatar answered Sep 30 '22 08:09

Oren Trutner