<VirtualHost *:80>
  DocumentRoot "D:/Projects"

Why doesn't this work ? How to access websites on the local box (Windows, Apache, MySql, PHP) which are based on IP address assigned by company's internal network which is not accessible to outside. When the laptop gets connected to internal network, all websites works, but when outside of the company network, these IP based url doesn't work even if all the code-base, development environment resides in the local Apache server on the laptop itself.

Is there a way to point 192.168.XX.XXX to

  • 1
    The long-term solution is Mobile IPv6; with this your laptop will always have the same IPv6 address everywhere you go. If you already have IPv6 at your company, you should see if your IT department can set this up. Feb 23, 2014 at 14:02
  • I am not sure about this IPv6 at present in the company. I will definitely ask, but is there any other way without changing anything at the company level or permanent change to do this. I am looking for a solution that can be applied on the laptop and when get into the company network it should work as it works usually. I was reading this.. Apache IP-based Virtual Host but not sure if it is the right way. Doesn't work either. Feb 23, 2014 at 18:38
  • @MichaelHampton s/long-term/very-long-term-not-gonna-happen-real-soon/ Feb 28, 2014 at 16:37
  • @quadruplebucky It will be soon enough. If you really want to talk about it, though, comments aren't ideal; try chat. Feb 28, 2014 at 16:40
  • Did you bother trying Option 2 in my answer as this is the way it should be really done. You need to use VirtualHosts and DNS. This way you can also simulate different environments.
    – ek9
    Mar 1, 2014 at 14:18

6 Answers 6


Option 1

Set ServerName to localhost like this:

ServerName localhost

Then access the server via


It will not matter what IP you have.

Option 2

First you setup VirtualHost like this:

<VirtualHost *:80>
  DocumentRoot "D:/Projects"
  ServerName projecthost

Then on windows you can always set an IP to which "projecthost" will point to. Edit C:\Windows\system32\drivers\etc\hosts file and add:




Then access the server via

  • It doesn't work. Also, when the IP( is being typed in the browser, it should not change the URL rather, it should point to local Apace server which is accessed by or localhost Mar 5, 2014 at 10:53

If you only intend to use one virtualhost you can use the apache default virtualhost. See: Apache Default Virtual Host

If you're hosting multiple virtualhosts edvinas provides the answer. Create a name for each project, and create a entry on your hosts file with that name pointing to which is always available.

  • So we cant have IP based ServerName in the virtual host configuration in Apache ? Like this: <VirtualHost *:80> DocumentRoot "D:/Projects" ServerName </VirtualHost> So any request made on that laptop with specific IP based url will point to the local Apache where the project has been setup ? Let me read the Apache Default Virtual Host. Thanks !! Feb 28, 2014 at 12:49
  • You can think of the ServerName as what you type at the browser URL and get redirected to that website. If you type and the servername is then you get to the right place, as long as works (happens on your office network) but doesn't when it doesn't resolve. always resolves to your local computer so you can use that one and access the site as, but other people won't be able to access it. That's the reason why default virtualhost is probably the best solution, but it all depends on what your requirements are. Feb 28, 2014 at 13:01

This doesn't work because the 'ServerName' parameter to Apache says effectively: If you get a request, make sure that the URL specified by the user has as the destination. When you are outside of your company network and not using that IP address (because you were assigned another), then your request will either:

  • Reach the Apache server but have a different IP address (either or whatever IP you were assigned by the foreign network), or
  • Not reach the Apache server because your computer doesn't know where is anymore (it has forgotten its former identity because it is irrelevant to its new network location)

If you only need the one web site (likely at this stage), I would recommend removing the ServerName line because it doesn't help you (as recommended by Manuel Sousa) and using locally, and when you are on your work network.

An example of a sub-optimal approach that might achieve the stated goal, you can try to configure your network card to have an additional IP address ( while you are not at work. Challenges:

  • This might not work if your external network has a dynamic IP address.
  • This will likely interfere with your computer functioning on your work network.

Again, I think this approach is a bad idea, but you can judge for yourself: http://social.technet.microsoft.com/Forums/windows/en-US/691d5aa4-09a3-4390-856a-26c10d773a3b/how-to-assign-differentmultiple-ip-address-to-nic-network-card?forum=w7itpronetworking


Do you have anything else (another Virtual Server, Perhaps) that Listens in ??

If not, you can very well edit the vhost to resolve for all traffic receiving in

  • the internal ip address(,, localhost: all points to the same one project directory under which I keep all projects as separate directories. Can you pls provide me what should be the content into the vhost file. Feb 23, 2014 at 18:50

What if you try a batch file that changes the host file (C:\Windows\system32\drivers\etc\hosts ) when you are outside the network and then another one when you are inside?

Have it set up so that when you are outside the corporate network, it adds this line:

And then another one to comment it out once you get into the corporate network like this:


Or just simply removing the line should also work.

This way, can keep the apache config intact and just make changes on your laptop.


  • It doesn't work. Also, I don't think we can point one IP to another in this manner in the hosts file. Mar 5, 2014 at 10:57

You can work around this with a dynamic DNS service that lets you use private address space. (I know dyn.com does, for example, but I have no opinion one way or the other on their services)

For example you'd use:

ServerName myapp-whatever.dyndns.org

in your apache conf and run an update client that supports using your interface address (not your detected public IP, which is what most do, but will break for you)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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