36

is it possible to create subdomains on my localhost? like sub.localhost and would like to know how subdomains work.

Mehman Manafov
  • 449
  • 1
  • 4
  • 8

3 Answers3

43

Create a virtual host as such:

<VirtualHost *:80>
    ServerName sub.localhost
    DocumentRoot "C:/public_html/sub"
</VirtualHost>

And in your hosts file add this line:

127.0.0.0       sub.localhost

Here is a useful tutorial you might find helpful.

SeanWM
  • 15,457
  • 7
  • 48
  • 82
  • *.localhost should resolve out of the box, without adding anything to /etc/hosts :) Although in Debian I have this exact problem – holms Sep 03 '18 at 15:05
10

You can make your browser to point to any domain/subdomain that you want as long as you put the ip - hostname definition in your c:\Windows\System32\drivers\etc\hosts file, for example:

127.0.0.1 localhost

127.0.0.1 sub.localhost

or on the same line separate by space:

127.0.0.1 sub.localhost subsub.localhost local.host

Community
  • 1
  • 1
SAnDAnGE
  • 428
  • 2
  • 6
6

Add the following to your local hosts file. On windows, it's located at C:\WINDOWS\system32\drivers\etc\hosts.

127.0.0.1       sub.localhost

Replace 127.0.0.1 with whatever IP address you want.

Athens Holloway
  • 2,107
  • 3
  • 17
  • 25