LinuxQuestions.org
Visit Jeremy's Blog.
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-31-2007, 12:37 AM   #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-31-2007, 12:59 AM   #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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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-10-2005 12:21 AM
find replace via html form topcat Programming 2 08-02-2005 07:13 AM
How to "Search & Replace" in html files using Perl? rebel Red Hat 8 04-09-2005 01:58 PM
how to replace html-file-content ??? ledauphin Linux - Newbie 2 03-08-2004 05:37 PM
Konqueror + file:/usr/share/doc/HTML/index.html jon_k Linux - Software 2 11-25-2003 06:06 AM


All times are GMT -5. The time now is 01:04 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration