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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |