I have a client who has built her entire site using html extensions. As such, renaming files and changing links just isn't an option. I need a way to include a footer file into each .html page. I've read a bit on the subject and initially thought html includes would be fine, but then realized they are only valid if the file extension is .shtml or something else. So are there any other alternatives? Any help is greatly appreciated.
-
2rather than finding alternatives, why not change it? make it "scalable" rather than being stuck in your situation of finding "workarounds" – Joseph Mar 26 '12 at 00:58
-
1FYI, Server Side Includes != PHP Includes – Phil Mar 26 '12 at 01:03
-
Normally I would, but I didn't originally build the site, and going through all of the files she has and renaming them and changing links is a nightmare that's not worth my time. – Willem Ellis Mar 26 '12 at 01:05
-
Why not just [parse `.html` files as PHP](http://stackoverflow.com/q/6237044/283366)? – Phil Mar 26 '12 at 04:18
-
For anyone to answer: should this question have been asked on http://webmasters.stackexchange.com/ ? I'm not implying the OP should have done so, just curious about the guidelines of StackOverflow – chharvey Jul 29 '13 at 07:39
7 Answers
Alternatives are all ugly :
- insert header and footer using iFrames
- use a HTML editor having template feature like Dreamweaver
- use a script of yours that will edit all HTML pages adding the header and footer
- insert header and footer using Javascript
- ...
All of those are very bad because the HTML page has no real header/footer (iframes, javascript), or it is hard to maintain.
Of course the best way is to make easy to maintain real HTML pages. That is turn the "changing links just isn't an option" into "let's change extensions and links". Some tools can help you to do that.

- 5,402
- 1
- 20
- 25
-
How about writing a .htaccess rule? So I change the file extensions to .php and then write a rule that points example.html to example.php. Would there be any SEO repercussions from doing this? – Willem Ellis Mar 26 '12 at 01:23
-
No SEO repercussion, several CMS already turn dynamic contents into HTML extension. But in your case, the .htaccess rewriting rule will need a listing of you pages, or it will need to rewrite all HTML extension into the PHP extension, which make you impossible to have real HTML extension. This is ulgy too. – Skrol29 Mar 26 '12 at 02:05
-
@Skrol29 I'm interested in bullet #2, HTML editor templates... can you explain those / redirect me to some resources? It would be nice for my snippets to be automatically and dynamically updated on my local drive ***BEFORE*** uploading to the server! – chharvey Jul 29 '13 at 07:42
An .htaccess rule would work, if you setup 301 redirects it will notify search engines of your change and there should not be any seo repurcussions. This will redirect that for you. The other benefit for seo is php includes are server side so the html will be passed to the search engine spider for index, where javascript will execute after the document loads, and most spiders are not going to execute your JS, just index the html passed down from the server.
RewriteEngine on
RewriteBase /
RewriteRule (.*).htm$ /$1.php [R=301,NC]

- 2,397
- 1
- 13
- 16
-
Awesome this helps a lot and will greatly reduce the time it's going to take to get this done! – Willem Ellis Mar 26 '12 at 01:43
You could accomplish this with javascript by creating a footer template in a separate html file and then dynamically load the footer template markup into each page through some javascript code.
Although, you would still have to modify each html file that you want a footer to appear on by adding the javascript code which adds the footer.
Other than that, there is no equivalent in html to includes or master pages. These are server side concepts.

- 2,248
- 18
- 24
-
THIS is a solution I've been searching for for a VERY long time. How in the world can you get JavaScript to access content from external HTML documents?? – chharvey Jul 29 '13 at 07:45
Use javascript or preferrably jquery. With this function you can just load external files into a div with 1 line. http://api.jquery.com/load/

- 2,397
- 1
- 13
- 16
I would suggest a major rewrite as some pointed out but, given your situation that you can't change the technology used, I am assuming it's a reasonably big site too, my suggestion is to use sed to include the footer code as you mentioned into each HTML file.
Either that or add the footer using Javascript, which is not a bad idea in your situation.

- 8,034
- 10
- 40
- 66
Maybe you can write a script that will append the footer to all the html files. So basically just copy the whole set of html files to a dev location and then run the script to output the new files.
Alternatively, copy and paste may be less time-consuming.
Javascript is probably simpler, but doesn't work when the user doesn't have js enabled.

- 10,608
- 2
- 29
- 35
Two ways to create client-side includes: javascript and iframe. While using javascript, the search engine will not see the included text. And iframe element must have a fixed width and height.

- 31
- 4