Difference between revisions of "How to enable server side includes"

From EPrints Documentation
Jump to: navigation, search
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
{{Version|since=3.2.1}}
 
{{Version|since=3.2.1}}
  
Note: you must have the [http://httpd.apache.org/docs/2.0/howto/ssi.html Apache Server Side Includes (SSI)] module installed and enabled.
+
You must have the [http://httpd.apache.org/docs/2.0/howto/ssi.html Apache Server Side Includes (SSI)] module installed and enabled.
  
Edit <tt>archives/[repoid]/cfg/apache.conf</tt> and add to the <tt><Location></tt> section <tt>AddOutputFilter</tt> and <tt>+Includes</tt>:
+
This enables you to add includes to the content of static pages. If you want to add dynamic content to the template you should do this via a template part in cfg.d/dynamic_template.pl.
 +
 
 +
===Configuration===
 +
 
 +
Edit <tt>cfg/apache/[repoid].conf</tt> and add to the <tt><Location></tt> section <tt>AddOutputFilter</tt> and <tt>+Includes</tt>:
 
   <Location "/eprints">
 
   <Location "/eprints">
 
     PerlSetVar EPrints_ArchiveID myrepo
 
     PerlSetVar EPrints_ArchiveID myrepo
Line 16: Line 20:
 
Restart apache.
 
Restart apache.
  
<!--#include virtual="/index.php"-->
+
===Example===
  
Example include:
+
&lt;!--#include virtual="/cgi/mydynbit"--&gt;
  
&lt;!--#include virtual="/cgi/mydynbit"--&gt;
+
==Issues calling cgi scripts with parameters (issue seen with v3.3.16 / Apache 2.4 / Ubuntu)==
 +
 
 +
When trying to include a URL with parameters, the EPrints stack will see the URL parameters of the main page, not the included request e.g. if this include:
 +
<source lang="xml">
 +
<!--#include virtual="/cgi/latest_tool?mode=test&mainonly=yes" -->
 +
</source>
 +
was used on the main index page, if the page was requested with no URL parameters, the <tt>latest_tool</tt> would not see the <tt>mode=test</tt>, or <tt>mainonly=yes</tt> parameters.
 +
 
 +
===Solution===
 +
The cgi script needs to determine whether it is the main apache request, or a sub-request (e.g. the SSI).
 +
 
 +
The following line, placed near the top of the cgi script appears to resolve the issue.
  
This enables you to add includes to the content of static pages. If you want to add dynamic content to the template you should do this via a template part in cfg.d/dynamic_template.pl.
+
<source lang="perl">
 +
local $session->{query} = CGI->new( $session->get_request ) if( !$session->get_request->is_initial_req );
 +
</source>
  
 
[[Category:Howto]]
 
[[Category:Howto]]

Latest revision as of 13:55, 19 August 2020

Warning This feature requires EPrints version 3.2.1 or later

You must have the Apache Server Side Includes (SSI) module installed and enabled.

This enables you to add includes to the content of static pages. If you want to add dynamic content to the template you should do this via a template part in cfg.d/dynamic_template.pl.

Configuration

Edit cfg/apache/[repoid].conf and add to the <Location> section AddOutputFilter and +Includes:

 <Location "/eprints">
   PerlSetVar EPrints_ArchiveID myrepo
   
   AddOutputFilter INCLUDES .html
   
   Options +ExecCGI +Includes
   Order allow,deny 
   Allow from all
 </Location>

Restart apache.

Example

<!--#include virtual="/cgi/mydynbit"-->

Issues calling cgi scripts with parameters (issue seen with v3.3.16 / Apache 2.4 / Ubuntu)

When trying to include a URL with parameters, the EPrints stack will see the URL parameters of the main page, not the included request e.g. if this include:

<!--#include virtual="/cgi/latest_tool?mode=test&mainonly=yes" -->

was used on the main index page, if the page was requested with no URL parameters, the latest_tool would not see the mode=test, or mainonly=yes parameters.

Solution

The cgi script needs to determine whether it is the main apache request, or a sub-request (e.g. the SSI).

The following line, placed near the top of the cgi script appears to resolve the issue.

local $session->{query} = CGI->new( $session->get_request ) if( !$session->get_request->is_initial_req );