0
INDEX
URL de la doc de mod_include
https://httpd.apache.org/docs/current/mod/mod_include.html
URL du tutoriel Apache
https://httpd.apache.org/docs/current/howto/ssi.html
Activation sur le serveur
ubuntu@ip:~$ sudo a2enmod include Considering dependency mime for include: Enabling module include. To activate the new configuration, you need to run: service apache2 restart
Configuration du htaccess
# Activation des SSI (Server-Side Includes) Options +Includes AddType text/html .shtml AddOutputFilter INCLUDES .shtml AddHandler server-parsed .shtml #Apache 2.4+ : SSILegacyExprParser on
Simple include d’un fichier existant (chemin relatif)
<!--#include file="includes/header.shtml" -->
Passage d’une querystring dans l’URL
Rechercher la variable theme dans l’URL https://www.test.com?theme=custom et fallback sur un thème par défaut si non trouvée :
<!--#if expr="$QUERY_STRING = /theme=([a-z]+)/" --> <!--#set var="theme" value="$1" --> <!--#else --> <!--#set var="theme" value="default" --> <!--#endif -->
Réaffichage de la valeur de la variable :
<body class="<!--#echo var="theme"--> index">
Tester la valeur en dur d’une querystring
<!-- ex : https://laposte.mobilite.localhost/job_v2.shtml?row1=0 --> <!--#if expr="$QUERY_STRING != /row1=0/" -->
Insérer une variable dans l’appel d’une variable
<!--#flastmod file="css/${theme}.css" -->
Formatage de la date en pseudo-timestamp YYYYMMDDHHmmss
<!--#config timefmt="%Y%m%d%H%M%S" -->
Liste des formats de date
%a | Abbreviated weekday name | Mon, Tue |
%A | Full weekday name | Monday, Tuesday |
%b | Abbreviated month name (also %h) | Jan, Feb |
%B | Full month name | January, February |
%c | current day & time of local server | 11/09/03 13:45:22 |
%C | current day & time in default format | 11/09/03 13:45:22 |
%d | Day of month as decimal number | 9 (not 09) |
%D | Date as %m/%d/%y | 28/09/02 |
%e | Day of month as 2-digit decimal number | 09 |
%H | current hour, 24 hour clock; 00-23 | 14 |
%I | current hour, 12 hour clock; 01-12 | 04 |
%j | Day of year as decimal; 001-366 | 254 |
%m | Month number; 01-12 | 11 |
%M | current minute; 00-59 | 45 |
%n | Insert a newline character | |
%p | AM/PM of local server | a.m. |
%r | Time as « %I:%M:%S AM | PM | 11:21:45 am |
%R | Time as %H:%M | 21:45 |
%S | current seconds; 00-59 | 32 |
%t | Insert a tab character | |
%T | 24 hour Time as %H:%M:%S | 12:32:34 |
%U | Week of the year (also %W) 00-51; Sunday first day of week |
49 |
%w | Day of week – Sunday first day; 0-6 | 04 |
%W | Week of the year 00-51; Monday as first day of week | 49 |
%x | current date formatted for servers locale | 10/09/03 |
%X | current time formatted for servers locale | 11:34:52 |
%y | Year number without century; 2-digit | 99 |
%Y | Year number without century; 4-digit | 1999 |
%z%Z | Time zone name/abbrev of servers time zone. | EET |
%% | A percent character. |
Création d’un killcache (chemin relatif)
<link rel="stylesheet" href="css/structure.css?v=<!--#config timefmt="%Y%m%d%H%M%S" --><!--#flastmod file="css/structure.css" -->"> <link rel="stylesheet" href="css/<!--#echo var="theme"-->.css?v=<!--#flastmod file="css/${theme}.css" -->" type="text/css">
Sortie :
<link rel="stylesheet" href="css/structure.css?v=20140705201954"> <link rel="stylesheet" href="css/kettner.css?v=20140705201832" type="text/css">
Killcache en chemin virtuel pouvant être appelé dans l’include d’un include
<script src="js/plugins.js?v=<!--#config timefmt="%Y%m%d%H%M%S" --><!--#flastmod virtual="/js/plugins.js" -->"></script> <script src="js/main.min.js?v=<!--#flastmod virtual="/js/main.min.js" -->"></script>
Afficher le document / l’URI courante
<!--#echo var="DOCUMENT_NAME"--> / <!--#echo var="REQUEST_URI"-->
Définir une variable selon la page courante
<!--#if expr="$DOCUMENT_NAME = adresse.shtml" --> <!--#set var="sitemap" value="0" --> <!--#elif expr="$DOCUMENT_NAME = cart.shtml" --> <!--#set var="sitemap" value="0" --> <!--#else --> <!--#set var="sitemap" value="1" --> <!--#endif -->
Tester la valeur d’une variable
<!--#if expr='"$sitemap" = "1"' --> <div id="sitemap"> ... </div> <!--#endif -->
Mettre du HTML dans une variable et l’afficher correctement
<!--#if expr="$QUERY_STRING = /theme=cariboom/" --> <!--#set var="banner" value="<strong>Frais de port offerts</strong> en s'inscrivant à la newsletter" --> <!--#else --> <!--#set var="banner" value="<strong>10% offerts</strong> dès votre inscription à la newsletter" --> <!--#endif --> <div class="text"><!--#echo encoding="none" var="banner"--></div>
Modifier le message d’erreur par défaut
[an error occurred while processing this directive] <!--#config errmsg="[Il semblerait que vous ne sachiez pas utiliser les SSI]" -->
Activer les server-side includes dans Nginx
Il faut que le module ngx_http_ssi_module soit activé : https://nginx.org/en/docs/http/ngx_http_ssi_module.html
Puis ajouter dans la configuration du site :
server { server_name rapport-annuel.pole-emploi.org www.rapport-annuel.pole-emploi.org; access_log /var/www/web/logs/access.log; error_log /var/www/web/logs/error.log; root /var/www/web/web; index index.shtml; location ~ \.shtml$ { ssi on; } }
Syntaxe SSI Nginx : inclure un fichier
Malheureusement il n’y a pas de moyen pour utiliser la même syntaxe qu’Apache.
Il faut ajouter un espace entre #
et include
:
<!--# include file="includes/header.shtml" -->
DATE 05 Juil 2014