Im running an Apache2 webserver on a local network.

I can access it through http://myserver/ . I have multiple web applications in their folders on server, so when I want to access app1 or app2 I put http://myserver/app1 or http://myserver/app2

I'd like to setup my server in a way I might be able to access applications like http://app1.myserver or something nice like that.

I bet in order to achieve this I need to setup a local DNS server or tinker with something like mod-rewrite. What approach would you choose? I have experiences with neither DNS server nor mod-rewrite.

Thanks for your answers.


Dns is useful to propagate names over the network. So, yes, if you want to have app1.myserver transformed into <>, you need a DNS server. But, if you are the only person using this (or for testing purpose), you can simply modify the hosts files on your local computer and add an entry for app1.myserver

Now, if you have 3 applications: app1.myserver, app2.myserver and app3.myserver. When you connect to one of them using http://app1.myserver, you browser sends an HTTP request that contains a "Host" Header. This Host header has the value "Host: app1.myserver".

Apache receives your HTTP request, looks at the Host header, and direct the request to the good application. This is called Virtual Hosting,and this is what you do when you create Apache's virtual hosts.

So, you don't need mod_rewrite, a basic Apache2 server, and a local Host file (or a DNS) and you're all set.

  • Just to clarify, you don't need to restart your local machine after editing the hosts file. Save the file and you should be able to access the site on the domain name straight away. – Abraham Brookes Mar 25 at 0:33

Possible Solution:

As you describe the scenario (local development at home) the quickest way is to set up manually a DNS entry in your machine. This way you avoid setting up a DNS server. (Why expend 2 hours setting a DNS when you can have it in 2 mins...)

You have to manually add an entry to Hosts files on all the machines in your network (that I guess is your server and your computer). If your server is and your local machine is

You have to add an entry in both machines similar to:

  • app1.myserver
  • app2.myserver

This way when you can access to your apps as http://app1.myserver or http://app2.myserver

How to do it?

  • If the machine is windows you have to add entry in C:\Windows\system32\drivers\etc\hosts
  • If it's a Linux go to /etc/hosts

Here you have more info for different OS: http://en.wikipedia.org/wiki/Hosts_%28file%29

  • I know about this option, but the fact is that I have multiple PCs that access my server and this would require to manually edit host files on each. Anyway, thanks for your answer. – NumberFour Oct 3 '10 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.