faqts : Computers : Internet : Web Servers : Apache

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 10 people (50%) answered Yes
Recently 5 of 10 people (50%) answered Yes


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:
To read the file, yourscript.pl is passed a variable: PATH_TRANSLATED.  
So if you're using Perl, a relevant code snippet might be:
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.