A handy trick I just learned: you can use your hosts
file to create subdomains of localhost
.
For example, I have WordPress and Drupal both running on my machine for local web development testing. I used to access one at http://localhost/wp
and the other at http://localhost/drupal
. This works just fine, in general, but can lead to some awkwardness with things like .htaccess
files and relative links when I move the site I’m developing to a real server.
By editing the hosts
file, though, I can access my development sites at http://wp.localhost/
and http://drupal.localhost/
, making it a little easier to test, migrate, etc.
In Windows (XP and Vista), you can find your hosts
file in the C:\Windows\System32\drivers\etc
directory. Add a couple of lines to the end of the file:
127.0.0.1 wp.localhost 127.0.0.1 drupal.localhost
And create virtual hosts in your Apache httpd.conf
to point those domains to the correct directories. E.g.:
<VirtualHost *:80> DocumentRoot D:\xampp\htdocs\drupal ServerName drupal.localhost </VirtualHost>
are you sure that its working fine?, for me its not working after restarting the Apache!
it’s not working for me too
but
how to create subdomain of subdomain on localhost
like
sajid.webspot.localhost,
nasir.webspot.localhost,
etc….
@Muhammad Sajid: You do that the same way. Just make a new entry in your
hosts
file andhttpd.conf
file for each new sub-sub-domain. Example:and