To create static versions of pages that get hit from the outside, I wrote this program, which runs as a cron job. It parses the .htaccess file of the webserver and creates static HTML versions of the pages listed in the .htaccess file. Currently, there is no parsing so that the redirect from the .htaccess gets generated as the output file, but as entries into the .htaccess file get made by another script, that's not as problematic.

#!/usr/bin/perl -w use strict; use File::Basename; use LWP::Simple; use Getopt::Long; GetOptions( 'wwwroot:s' => (\my $wwwroot), 'staticdir:s' => (\my $outdir), 'server:s' => (\my $server), 'node:i' => (\my @nodes), 'htaccess:s' => (\my $htaccess), 'savepath:s' => (\my $savepath), ); $wwwroot ||= './public_html'; #$htaccess ||= "$wwwroot/.htaccess"; $server ||= "perlmonks.org"; $savepath ||= $wwwroot; my $uri = "http://$server?node_id=%d;style=static"; my $save = "$savepath/%d.html"; # -d $wwwroot or die "wwwroot: '$wwwroot' is no directory."; -d $savepath or die "savepath: '$savepath' is no directory."; if (! scalar @nodes) { open my $hta, "<", $htaccess or die "Couldn't read '$htaccess' : $!"; push @nodes, map { /^\s*RewriteCond %\{QUERY_STRING\} node_id=(\d+ +)\$/ ? $1 : () } <$hta>; }; for my $node (@nodes) { my $url = sprintf $uri, $node; my $target = sprintf $save, $node; print "Saving $node via $url to $target"; printf ", %d\n", mirror($url, $target); };

In reply to dump-static-nodes.pl - Pull content from your webserver according to .htaccess by Corion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.