Welcome to WebmasterWorld Guest from

Forum Moderators: phranque

Message Too Old, No Replies

Nesting SSI

A way to nest SSI

4:48 am on Mar 9, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 11, 2007
votes: 0

I am sure for most people here this is known. But I couldn't find it while looking around here, so I thought I would post it in case others were looking as I had. I don't know whether this way is a good way or a secure way. Perhaps more experienced people can correct this if it suggests an unwise procedure.

I wanted to nest ssi. My web pages have .html endings rather than .shtml I had put a line in my .htaccess file that allowed the .html file to do an include. The problem was that if I had another include in the file called by the include, the second include would not work.

For example:

The .html file calls the includeA.txt file.

The includeA.txt file calls the includeB.txt file.

But the includeA.txt file would not successfully call the includeB.txt file.

The first SSI include comand is in an html file.

Having this:

"AddType text/x-server-parsed-html .html"

in the .htaccess file allows the .html file to run the includeA.txt command in the .html file. Apparently, normally a file that includes an SSI command is to have a .shtml ending.

In the .html file is this include command to call the includeA.txt file:

<!-- start include includeA -->
<!--#include virtual="includeA.txt"-->
<!-- end include includeA -->

The above command calls the inlcudeA.txt file and includes it in the .html file.

In the includeA.txt file is this include command to call the includeB.txt file:

<!-- start include includeB -->
<!--#include virtual="includeB.txt"-->
<!-- end include includeB -->

My goals was for this to include the includeB.txt file, ultimately in the .html file.

The system would include in .html file the includeA.txt file, including the command to call the includeB.txt file, but the includeB.txt file itself would not be included.

I think because normally a file that is to inlcude a ssi command is to have a .shtml ending, I was able to get it to work by changing the endings of the two files to be included from .txt to .shtml. I left the .html file with the .html ending.

This made everything work. So now the .html file contains:

<!-- start include includeA -->
<!--#include virtual="includeA.shtml"-->
<!-- end include includeA -->

which includes the includeA.shtml file which contains:

<!-- start include includeB -->
<!--#include virtual="includeB.shtml"-->
<!-- end include includeB -->

which also includes the includeB.shtml file in the .html file.

So now the content of both appear in the .html file.

I didn't try it, but perhaps I could have left the .txt ending on the includeA.txt and include B.txt files if I had changed the above .htaccess file to

"AddType text/x-server-parsed-html .html .txt"

[edited by: 4thePegeh at 4:52 am (utc) on Mar. 9, 2007]

5:16 am on Mar 9, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

Also see the XBitHack directive in Apache mod_include [httpd.apache.org].


6:22 am on Mar 9, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 11, 2007
votes: 0

Thank you.

From that it looks to me like the xbithack is the preferred way to go because it means only the specified .html files will be parsed and the others wont, therefore the others have shorter load times.

If all of the .html files will have ssi, then would the two methods be a tie?

Also, it occurs to me that resources could also be saved if in a string of nested ssi, the final file to be included were given an ending that the server was not to parse. So it would parse each nested include file except the last one which would simply be included, but not checked for whether it had any include commands. I read a thread here earlier where someone used .inc for their included files so I ended the final file with that and it got included, but I assume, it did not get checked to determine whether it wanted to include anything.