I had to do this earlier today for a client who's previous web programmer decided to take a round the world vacation without first handing over the system or providing any documentation. This technique allowed me to backup the site and create an identical looking site in about 20 minutes.
This is also a technique for publishing scripted pages on free hosts
. Supposing your original site makes use of Ldap
servers, Database queries and other kinds of server side complexity - the copy site gives a similar appearance without any of the internal complexity.
What we are going to do:
We are going to use wget to traverse every linkable page of the source web-site, and have it copy the HTML and graphical content of each page into static files. Next we are going to use apache's mod rewrite and a tiny PHP (or Perl) script to serve up those pages and create the illusion that they are still running dynamically.
What you need:
- A functioning apache 1.3 webserver to run the copy site.
- Enough disk space to hold static versions of every possible page and image that can appear on the site.
- The unix command line utility 'wget'; for copying the web pages over.
- A basic text editor - I like jedit.
- PHP (or similar) installed as an apache module.
Make a new folder to store the new web pages you are about to copy. On a Linux computer this will usually be somewhere within /var/www/html. Change to that directory.
Use wget to copy the website over to your computer.
wget -r -t5 http://foo.net/ -o download.log
This means: Recursivly download everything you can find on foo.net, if you cannot fetch something keep trying 5 times and record all the progress in the file called "download.log".
Setup your apache virtual hosts file and your local DNS server (or /etc/hosts file) so that you can see the website you have just copied over on a convenient URL on your computer. This makes it easy to find your copied web-site and test the next step.
In any folder where you can find HTML pages, insert a .htaccess script that looks something like this:
RewriteRule (.+) page.php
This says, if any pages other than "/" (the default page) are requested from this directory, rather than attempting to display the specified page, just run a script called page.php.
Page.php needs to be something like this:
// This is the folder from which all relative URLs are derived.
// This is the filename that I shall retrieve.
if (! is_null( $_SERVER["REQUEST_URI"] ) )
$file = $base_path . $_SERVER["REQUEST_URI"];
die ("No file to get");
// Comment out this next line once you have it working, it's a security risk.
echo "<!-- This content was read from: ".$file."-->";
// Limit the page length to aprox 100kb
echo fread( $fp, 100000 );
Step 5: Restart your apache server.
On a red-hat Linux box do:
Update: I've recieved a number of messages outlining more elegant solutions than the one I propose. PERL programmers will appreciate w3mir, a package that does almost exactly the same thing but with many extra features.