[TAG] Fixing absolute links in a mirror

Ben Okopnik ben at callahans.org
Sun Jul 18 19:11:28 MSD 2004


On Sun, Jul 18, 2004 at 11:55:00AM +0100, Paul Nolan wrote:
> On Sunday 18 July 2004 02:21, you wrote:
> > Can you send us an example of what it currently looks like, and what you
> > want it changed to?
> Well, the links are currently like this:
> <a href="http://www.somewebsite.co.uk/blurf/foo.html">, and they should be 
> something like "../foo.html" or "foo.html" instead. I've attached one of the 
> pages so you can see what I mean.

It looks like your 'somewebsite' is "http://www.square-central.com/",
with the rest being off-site links. Simple enough; I suggest that you
save a copy of your mirror - just in case things don't work out the way
you expected - and run

(all following code is untested, but should work fine):


``
perl -i -wpe 's{http://www.square-central.com/}{}g' *html
''

in the directories containing the HTML. If you've got a lot of
directories with deep subdirectories, or something else that would make
the job terminally tedious, then you could wrap the above in a "find"
statement; this would execute it for every directory from the starting
one down:

``
find /my/top/html/dir -type d -exec perl -i -wpe \
's{http://www.square-central.com/}{}g' {}/*html \;
''


* Ben Okopnik * okopnik.freeshell.org * Editor-in-Chief, Linux Gazette *
-*- See the Linux Gazette in its new home: <http://linuxgazette.net> -*-




More information about the TAG mailing list