DougN
DougN

Reputation: 4617

Apache SSI and variable

I've got a 10 year old Apache server (FreeBSD) where the following works:

File1.htm

<!-- #set var="myDir" value="/dir" -->

File2.htm

<!-- #include virtual="File1.htm" -->    //sets myDir
<!-- #include virtual="${myDir}/File3.htm" --> //loads /dir/File3.htm

File3.htm

<!-- #include virtual="${myDir}/File4.htm --> //loads /dir/File4.htm

On a very recent Suse Linux with the latest Apache, it seems that myDir is not defined in File3.htm, and thus it can't find and load File4.

So File2 can load File3, but File3 fails to load File4. It works in the 10-year old Apache on FreeBSD, but not on a recent Apache on Linux....

Any ideas?

EDIT For completeness' sake, this is basically the config file:

DocumentRoot "/srv/www/htdocs"
<Directory "/srv/www/htdocs">
        Options Includes
        AddType text/html .htm
        AddOutputFilter INCLUDES .htm
        AllowOverride None
        Order allow,deny
        Allow from all
</Directory>

Upvotes: 2

Views: 2067

Answers (1)

user1419445
user1419445

Reputation:

I've made a test on my Ubuntu 11.04 system (with Apache 2.2.17), and I've had no problems at all.
Here are the files I've used:

File1.htm (located in the same folder of File2.htm)

<ul>
    <li>
        <p>Start File1</p>
        <!--#set var="myDir" value="/test/stackoverflow/ssi" -->
        <!--#echo var="myDir" -->
        <p>End File1</p>
    </li>
</ul>

File2.htm (located in the same folder of File1.htm)

<!DOCTYPE html>
<html>
    <head>
        <title>Apache SSI test</title>
    </head>
    <body>
        <ul>
            <li>
                <p>Start File2</p>
                <!--#include virtual="File1.htm" -->
                <p><!--#echo var="myDir" --></p>
                <!--#include virtual="${myDir}/File3.htm" -->
                <p>End File2</p>
            </li>
        </ul>
    </body>
</html>

File3.htm (located in the "ssi" subfolder)

<ul>
    <li>
        <p>Start File3</p>
        <p><!--#echo var="myDir" --></p>
        <!--#include virtual="${myDir}/File4.htm" -->
        <p>End File3</p>
    </li>
</ul>

File4.htm (located in the "ssi" subfolder)

<ul>
    <li>
        <p>Start File4</p>
        <p><!--#echo var="myDir" --></p>
        <p><!--#echo var="DATE_LOCAL" --></p>
        <p>End File4</p>
    </li>
</ul>

This is my ".htaccess" file:

Options +Includes
AddType text/html .htm
AddOutputFilter INCLUDES .htm

And here is the output that I get by requesting the page "File2.htm" in my browser:

  • Start File2

    • Start File1

      /test/stackoverflow/ssi

      End File1

    /test/stackoverflow/ssi

    • Start File3

      /test/stackoverflow/ssi

      • Start File4

        /test/stackoverflow/ssi

        Thursday, 30-Aug-2012 21:45:57 CEST

        End File4

      End File3

    End File2


You should also:

  • Check the permissions on all the .htm files and on the include folder (in your example should be the "/dir" folder), just to ensure that all the files are readable by the web server.
  • Check for errors in your Apache error log

By the way, I suppose that the missing closing quote in your "File3.htm" is only a typo.

Upvotes: 2

Related Questions