Forum Moderators: phranque
Consider the following code below:
<html>
<body>
Some text should appear...
<p>
<!--#include virtual="sometext.txt"-->
<?php include('sometext.txt');?>
</p>
</body>
</html>
I have three objectives:
1. to run php.
2. to run php within .html and .htm files.
3. to have .txt files included as SSI execute.
1 & 2 resolve by adding:
AddType application/x-httpd-php5 .php .html
to my .htaccess file. Works fine and executes PHP for .php and .html files, but the .txt SSI don't display.
3. I am not so sure about. Have tried a myriad of variations the least of which is
AddHandler server-parsed .txt which does display the .txt file include.
I know a workaround is to change <!--#include virtual="sometext.txt"--> to <?php include('sometext.txt');?>, however I would like both implementations to work.
Any assistance, greatly appreciated.
Kind regards, Andrew
You best bet is to go with the PHP solution, as it is 20 years 'more modern.'
If you have some legacy files where you only want to include SSI and not PHP, then you have the option to enclose the "AddType" and/or "AddHandler" directives within a <FilesMatch> section.
Jim
To jdMorgan:
Since I have just upgraded (what I would describe as a legacy site) with php tags in every page of the site for visitor analysis, it is perhaps now easier to run a script to upgrade all the <!--#include virtual="sometext.txt"--> tags to <?php include('sometext.txt');?> tags for consistency.
To Caterham
Admittedly, beyond enabling php, I seldom mess with .htaccess.
Given our current implementation of Apache(2.2.13 (Unix)), I assume SSI is implemented as an output filter (as I read mod_include has been implemented as an output filter since Apache 2.0).
I read the Apache Module mod_include, and remain a little confused as to the order of implementation, and indeed syntax in the .htaccess file.
For example:
AddType application/x-httpd-php5 .php .html
Options +Includes
AddType text/plain .txt
AddOutputFilter INCLUDES .txt
doesn't work, perhaps you might offer a further lead in the right direction, otherwise I would fall back to the solution in my reply to jdMorgan above.
Kind regards, Andrew