LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-30-2007, 11:37 PM   #1
donv2
Member
 
Registered: Nov 2004
Location: Upper right corner of USA
Distribution: Ubuntu/Mint, unSLUng (NSLU2), Arch/PlugApps (Dockstar)
Posts: 50

Rep: Reputation: 15
Question Search & Replace Technique to Fix html HREFs w/o html extension


I'm trying to fix an inherited web site where the prior regime used html files that were named without the .html extension. The new webhost does not understand how to serve these files (but works fine when the file is renamed with the .html extension added).

I've figured out how to find the affected files using grep, so I can script the renaming of the files to add the extension fine. The problem is that the files have cross-reference HREF URLs which use the "base" vs "base.html" syntax, so I need to edit the content of the files too.

I was hoping to be able to automate this task, but I've not yet found a way to do this simply via a conventional regex based search & replace (eg with a perl 1-liner) that accounts for the fact that some HREFs have extensions and should be left alone, but any being without one need to have it added. The only good news is that any "non-extension" HREF is definitely meant to be .html... so no further distinction is necessary.

Example:
Code:
href="polarityrealizationtherapy"
should be
href="polarityrealizationtherapy.html"
but
href="http://www.polaritytherapy.org/polarity/index.html"
and
href="polarity_brochure.pdf"
should be left unchanged
Any hints for techniques to use in this situation? Thanks!
 
Old 01-30-2007, 11:59 PM   #2
donv2
Member
 
Registered: Nov 2004
Location: Upper right corner of USA
Distribution: Ubuntu/Mint, unSLUng (NSLU2), Arch/PlugApps (Dockstar)
Posts: 50

Original Poster
Rep: Reputation: 15
Talking MUCH simpler solution...

Nevermind... I found a much easier solution!

All it took was teaching this server to do the same thing apparently the old host did... serve up blank extension files as html. To do this I added a .htaccess file in the directory for these files with the following content:
Code:
DefaultType text/html
Works like a charm.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
search an html-based CD-catalog pavodive Programming 1 08-09-2005 11:21 PM
find replace via html form topcat Programming 2 08-02-2005 06:13 AM
How to "Search & Replace" in html files using Perl? rebel Red Hat 8 04-09-2005 12:58 PM
how to replace html-file-content ??? ledauphin Linux - Newbie 2 03-08-2004 04:37 PM
Konqueror + file:/usr/share/doc/HTML/index.html jon_k Linux - Software 2 11-25-2003 05:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration