Adding links to content on the fly, not sure how to describe this

Discussion in 'Programming' started by ferret77, Nov 24, 2006.

  1. #1
    How could you mass add links to a bunch of static html pages based on text in the html

    like say I want every instance of the word dog to link to a dog page on a site,

    I mean it would be really simple to either do a mass find and replace using a text editor, or if I loaded the site into db

    But is there a way to do it on the fly at the server level?
     
    ferret77, Nov 24, 2006 IP
  2. symmetric

    symmetric Peon

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Since you have a static site, I'll assume you don't want your page extensions to change and that you don't want to break existing links.

    One approach that could work is something like the following:

    1. Use mod_rewrite (assuming Linux) to rewrite your URLs so that they can be routed through a PHP page (or a page in some other scripting language). For example, yourdomain.com/dir/pagename.htm could be rewritten as yourdomain/link_stuffer.php?file=/dir/pagename.htm

    2. Your PHP script (link_stuffer.php in the example above), would get the page name from the query param, read the static file from disk, generate links on the fly and return the content to the user.
     
    symmetric, Nov 24, 2006 IP
  3. ferret77

    ferret77 Heretic

    Messages:
    5,276
    Likes Received:
    230
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I am not looking to re-write the urls

    I want to rewrite the pages as they are being outputed
     
    ferret77, Nov 25, 2006 IP
  4. kiwwi

    kiwwi Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Not sure about this, but I first think about using javascript (you have to add small script on every static page, or configure apache to add to each .html this script to the end). This script will traverse every <p> or whatever element on the page and rewrite phrases to <a> link.
     
    kiwwi, Nov 25, 2006 IP
  5. ferret77

    ferret77 Heretic

    Messages:
    5,276
    Likes Received:
    230
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yeah maybe javascript, I was kind of trying to do what that intellitext affiliate does but add links of my choice
     
    ferret77, Nov 25, 2006 IP