So here is the technique to make sub domains on localhost.
You can also use this to host more than one site on localhost. i.e, you can host multiple sites situated on different folders.
PS: This is for Apache-Windows configuration. (If you have info about other Server-OS configs please let me know.)
Steps
First decide on the subdomain names...
for eg:
sub.localhost, sub2.localhost, alt.localhost , images.localhost etc..
You can also name www.name.com. (Please note that if there is a site with that name on the net, you wont be able to access that site on the internet.)
Second making these sites to point to 127.0.0.1, for this you can edit the HOSTS file on windows. See this about the HOSTS file.
Now add to HOSTS line
127.0.0.1 hostname
Egs:
127.0.0.1 sub.localhost
127.0.0.1 sub1.localhost
127.0.0.1 sub2.localhost
127.0.0.1 images.localhost
127.0.0.1 www.mysiteonmycomp.com
Next we have to assign each of these different URL's to different folders.
This is done on the apache conf file. (httpd.conf file situated in apache\conf\ directory)
Scroll all the way down the httpd.conf file until you reach about Virtual Hosts.
Add
NameVirtualHost *:80 #(This line was commented before)
ServerName subdomain name.localhost OR yoursite.com
DocumentRoot Path to the server root, See examples.
DirectoryIndex index.php index.html index.html index.htm index.shtml
Egs:
ServerName sub.localhost
DocumentRoot "C:/public_html/sub"
DirectoryIndex index.php index.html index.html index.htm index.shtml
ServerName images.localhost
DocumentRoot "C:/public_html/images"
DirectoryIndex index.php index.html index.html index.htm index.shtml
ServerName site.com
DocumentRoot "C:/public_html/site"
DirectoryIndex index.php index.html index.html index.htm index.shtml
Test the configurations (using apache -t)
All done!
No comments:
Post a Comment