Forum Moderators: open

Message Too Old, No Replies

Server Side includes in HTML files

I need a way to include files without changing file extension

         

SilverLining

5:38 pm on Dec 1, 2005 (gmt 0)

10+ Year Member



Hi all

I have a site where the navigation is reapeated on all html pages (static code within each .html file). Footers are also repeated on all pages. Problem is, I want this code to be centralised - could use SSI or convert to .shtml (much easier to maintain), but ideally I dont want to change the file names due to Google indexing.

Please advise. Thanks

ogletree

5:46 pm on Dec 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would use php includes. Add:

AddType application/x-httpd-php .html

to your .htaccess file.

Then

include 'header.php';

This way if you ever think of some neat php things to add you can easily do it.

kaled

8:41 pm on Dec 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your server is running Apache, and has the "x bit hack" enabled, SSI can be enabled by setting the execute bits of the file attributes.

Kaled.

SilverLining

6:45 pm on Dec 6, 2005 (gmt 0)

10+ Year Member



Thanks for the replies! I'll probably go with ogletree's response. Was hoping to get by with my current hosting package, but will see. Cheers

topsites

1:19 am on Dec 7, 2005 (gmt 0)



Use pure html and a text editor with a global find-replace function. So open ALL your html files inside the editor, then do a Find/replace and use copy-and-paste to paste the old header or footer in the find section then paste the new header or footer in the replace section, select 'All Open Documents' click confirm and seconds later all your pages are done, all you got left to do is ftp which you block the whole slew of files with the mouse, and drag and drop.

Might involve a little more work the first time around to ensure all your pages have the same header and footer, but no worse than turning on ssi... which I have never used because not all hosts provide it.

For the name of the program, I use Cute Html.

SilverLining

9:59 am on Dec 7, 2005 (gmt 0)

10+ Year Member



thanks topsites, but the whole idea is to have one file, one change and there is no room for error. one is bound to overlook one little thing somewhere.

esllou

10:13 am on Dec 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I used topsites' method for a year on a 2000 page site and damn near went crazy. Would be lost without ssi now.

The method chosen in previous posts would not be allowed by my host who have a "call a spade a spade" attitude towards these things and don't want server load wasted by parsing every page for php or ssi that isn't there.

teylyn

10:56 pm on Dec 15, 2005 (gmt 0)

10+ Year Member



Hi, don't want to open a new thread, since this is along the lines of my question. My situation is a bit different. My site is hosted on Microsoft-IIS/5.0 and the last time I had to change some of the file names in my site, the hosting company had to do the 301 redirects for me, since there is no .htaccess that I can manipulate.

Now I'm in the process of redesigning my site in XHTML strict and pure CSS (yeah!). It just struck me that I should find a way of including the repetivive code for the navigation -- as said before, just one file to make errors in. All pages are static html, anyway.

But from what I read here and elsewhere, that would mean that I have to rename all my pages to *.shtml.

So, with my limited technical abilities, no hands-on access to the hosting server and the prospect of asking the hosting company to YET AGAIN create half a zillion 301 redirects on their server, is there any other way of doing this?

I just ran a check with a test file and find that .htm and .php files will be included just fine, but only if the calling file has the .shtm extension.

Am I back in the navigation-in-all-the-individual-html-files scenario?

Any comment welcome.

cheers

teylyn

pageoneresults

11:12 pm on Dec 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So, with my limited technical abilities, no hands-on access to the hosting server and the prospect of asking the hosting company to YET AGAIN create half a zillion 301 redirects on their server, is there any other way of doing this?

You could always use FrontPage includes...

<!--webbot bot="include" u-include="http://www.example.com/nav/top.asp" tag="body" -->

As long as the server has FP Extensions installed, the above code will work just fine. You'll need to familiarize yourself with using FP includes as they are set up a little differently than SSI. An FP include contains all of the <head></head> data that a normal page contains. In fact, it is a normal page with the exception that it only contains the elements you are including into other pages.

I was going to say search WebmasterWorld for FrontPage Includes because I have a tutorial floating around here somewhere but the search is not working yet. :(

pageoneresults

11:14 pm on Dec 15, 2005 (gmt 0)

teylyn

1:01 am on Dec 16, 2005 (gmt 0)

10+ Year Member



Thanks for this, pageoneresults!

I ran the test, but, alas, the server apparently does not support FP extensions.

Just out of curiosity (since I'm not a Frontpage user, originally from the Dreamweaver camp but now happy with hand coding), tell me please: will only the tag identified in the calling page be included in the html of the page or will the whole header section be included too?

cheers

teylyn

pageoneresults

2:17 am on Dec 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just out of curiosity (since I'm not a Frontpage user, originally from the Dreamweaver camp but now happy with hand coding), tell me please: will only the tag identified in the calling page be included in the html of the page or will the whole header section be included too?

When the FP Extensions are installed, the FrontPage <webbot> functionality is available. FP uses a very similar process to SSI but in its own unique way. The only content that is included in the page is that between the <body></body> of the include page. I spell this one out in the tutorial above. If the FP Extensions are not installed and you use the above <webbot> for an include, you will then see multiple <head></head> (one for each include) elements as the Include Page component does not function without the Extensions.

What's nice about the FP Include Component is that it functions pretty much without fail (if set up properly) and provides the same functionality that SSI does without having to get the Server Administrator involved, nor do you have to deal with changing file name extensions. Your include files can be of any file type. You just drop those include tags wherever you need them and presto, you've got instant SSI. :)

Keep in mind that if you are using .asp pages, then your includes files will be .asp. If you are using .htm, then your include files will be .htm. Keep them matched up. In all actuality, if you were using FrontPage and had an .asp include file on a .htm page, it would display a component error. So, it is best to keep everything matched up.

pageoneresults

2:38 am on Dec 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do you have a Control Panel for your website? If so, there is probably an area where you can click a button and install FP Extensions for your site (takes about 15 seconds). Most offer this type of functionality as it is on a site per site basis.

teylyn

8:35 pm on Dec 19, 2005 (gmt 0)

10+ Year Member



Issue resolved.

My ISP made some changes on their server, so I can now #include with *.htm pages as well.

Thanks, pageoneresults for your help.

One question for clarification, though: If I #include html code, this code will be picked up by the search engines, won't it? So, if i put my navigation in a separate file and use #include to place it on the page, the bots will find the links to the other pages that are in the included code, I hope.

Some confirmation would be great.

cheers

teylyn

pageoneresults

8:48 pm on Dec 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks, pageoneresults for your help.

lol! Did you show them this topic? They probably saw that I was recommending FP Extensions be installed and they had a fit, huh? Snicker, snicker, snicker.

Yes, your included content will get spidered barring any other html issues that may be present. What you see when you view source at the browser is what the spider sees.