hosts file and multiple sub-domains
-
21-08-2019 - |
Question
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!
Solution
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.
OTHER TIPS
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
You may try AngryHosts, with which you can add wildcard hosts rules.