Domanda

Does anyone know an easy way to go in and apply code to about 16,000 individiual static hard-coded HTML pages? Situation: my client has an ecommerce site with over 16,000 product pages, but instead of dynamically creating the pages with a data feed, they hard coded the pages. (product1.htm, product2.htm, etc. etc.)

I need to be able to go in and add a snippet of code to ALL of their pages, but they don't have a universal footer or header to add it to them easily.

Does that mean I need to go in and hand add it to every single htm page? Or do you know of a program or script that can add a snippet of code to every page like a shell script or something?

I'm not sure how to go about this, and I don't want to spend hours editing thousands of pages.

Thanks, in advance, if anyone can help.

È stato utile?

Soluzione

There are numerous ways you can go about solving this.

  1. You could use a bash script to open all the files and prepend a header and append a footer. This will however change all the files.

  2. You could also use Apache's mod_rewrite to add the header and the footer dynamically.

    If you take for example the page

    /this/is/my/static/page.html

    you could use mod_rewrite to change requests to:

    modifypage.php?url=/this/is/my/static/page.html

    This modifypage.php file should then take care of adding the header and footer.

  3. A third solution is by using Apache Handlers.

    See: http://httpd.apache.org/docs/2.2/handler.html

  4. Use some macro in your editor to add header and footer to all the files.

  5. I bet there are more ways, but this is what I can come up with from the top of my head. Good luck!

UPDATE I wrongly assumed you were using Linux/Apache. I will leave this answer here, because it might be useful. However I bet there are similar solutions for your webserver! Look into 'pre processing and filtering' for your webserver.

Altri suggerimenti

If your working in a linux system you could write a bash script that could go over all the files and simply append a certain amount of text infront of all the files, maybe something like this could work for you:

#!/bin/sh

for file in *.html
do

echo "add text here" >> $file

done
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top