I Moved My Website to Another, Hosted Server and Now I Can’t Access Software on My Local Server!

It’s not unusual for someone to move their website from one server to another, whether from their own server to a hosted service, or from a hosted service to their own server, or from one host to another. Usually, if you have even a rudimentary understanding of how it all works, the move is smooth, with few if any glitches.

But an interesting situation can occur when you move a website from one server to another, but you still use the original server, and you still need to access software which is installed in the original directory or subdirectories belonging to the website which you have moved.

For example, if you have been hosting http://www.example.com on your own server, and then you move www.example.com to Host.net, when people point their browsers at http://www.example.com, they will end up viewing the files which reside on Host.net under “www.example.com”.

However, if you have not deleted them, you will still have all of the example.com files on your own server, in a directory which will probably look like this:
/www/example

So you might have on your server, for example, /www/example/index.html. Loading this would show you the exact same thing which visitors to the newly hosted http://www.example.com/index.html see, only you are looking at the file still on your original server, while they are looking at the one on the shiny brand new website host.

The problem is, of course, how are you going to tell your browser to get to that file on your local server? If you point your browser to http://www.example.com, you are going to end up at the new host, not your original local server.

So, instead you point your browser to your local server’s IP address, with some extra information. Let’s say that IP address is 127.0.0.1, you would do something like:
http://127.0.0.1/example/index.html, and that will get you to that file.

Ok, with me so far?

Great!

This will work for most things which remain on the original location of the site.

However, as it turns out, some programs which are installed to be run off a website do not like it when you come in directly using an IP address – they want to see that you came in using the domain. This is a problem because typing in “http://www.example.com” on your web browser takes you to, well, www.example.com.

So, how do you get around this?

You create a new subdomain, and you point that at your old server.

For example, at your registrar’s, you have indicated that “www.example.com” should go to Host.net’s IP address – let’s say that’s 192.168.0.1. (This is called an “A record”, and tells the DNS system that when people are looking for webpages at www.example.com, they should go to 192.168.0.1.)

Now you create a new A record for “subdomain.example.com”, and that indicates that when someone is looking for subdomain.example.com, they should go not to 192.168.0.1., but 127.0.0.1 (your old server).

This will allow you to browse in using a domain name rather than the bare IP address.

But not yet.

First you have to edit your Apache httpd.conf file to tell Apache that subdomain.example.com should really resolve to /www/example on your server.

Here is how that code should look in the httpd.conf file – this code assumes that you are doing virtual hosting, which, if you are interested in this post, and have read it this far, you almost certainly are:

[virtualhost 127.0.0.1]
ServerName subdomain.example.com
#ServerAlias subdomain.example.com
DocumentRoot /www/example
[/virtualhost]

(Note: change the left and right square brackets in the above snippet to < and > respectively; square brackets were used here to make sure that your browser shows you the full text, rather than rendering it as html code.)

Don’t forget to restart Apache when you are done editing httpd.conf!

Voila! This should work for most purposes!

Many thanks to my friend Daniel for his assistance with this!