Entry
Can I Change all links/images on the site from relative to absolute without changing HTML?
Nov 15th, 2001 15:12
Anthony Boyd, Jacob Singh,
You'll need to add an action to Apache's httpd.conf file:
Action text/html /cgi-bin/yourscript.pl
What this will do is pass every HTML file to a program called
yourscript.pl, and that program can convert all the links. You will
need to write yourscript.pl, or whatever you decide to call it. Using
Perl, you would rely on the "rel" method of the URI module:
http://www.perl.com/CPAN-local/doc/wwwman/libwww/lib/URI/URL.html
To read the file, yourscript.pl is passed a variable: PATH_TRANSLATED.
So if you're using Perl, a relevant code snippet might be:
open(FILE, "$ARGV{'PATH_TRANSLATED'}");
From there, you can read in the HTML and manipulate the links as you
wish, probably using a regex to grab 'em and the URI module to
change 'em. Then print the file to STDOUT. Viola, you rewrote the
links but the HTML files are left unchanged.