rss
twitter
  • Showcase
  • Carrières
  • Support
  • GitLab
  • Espace client
  • Contact

Pense-bête Apache Server-Side Includes (SSI)

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
by : Germain
Author / Auteur

Social Share / Partager

    Leave a Reply / Répondre Annuler la réponse

    *
    *

    Search the blog

    Blog categories

    • Workflow (1)
    • Front-end : HTML, CSS (13)
    • Front-end : javascript, jQuery (33)
    • Back-end : PHP, CMS (42)
    • Back-end : SQL, MySQL (20)
    • Sysadmin : Linux, Apache, GIT (75)
    • Designers : tools, advice (2)
    • Desktop : OS X (37)
    • Desktop : Microsoft (12)
    • Uncategorized (8)

    ITALIC™ Resources

    • Paramètres de connexion au serveur mail
    • Graphistes : séduire un développeur web
    • Dév front : nos bonnes pratiques
    • Mailing : nos (bonnes ?) pratiques
    • Environnement de travail Mac

    Recent comments

    • Germain dans Inserer un motif dans une forme InDesign
    • Fannie J dans Inserer un motif dans une forme InDesign
    • Rapide benchmarks de clients Git pour Linux (et un peu Windows et Mac aussi) – Haha. dans Git avec SourceTree : ouvrir dans TextMate / ouvrir dans Sublime Text 2
    • Germain dans Ajouter des contacts non-Facebook à Spotify
    • cc dans Ajouter des contacts non-Facebook à Spotify

    Meanwhile, in the office…

    UNEP @ Paysalia

    01 Déc 2015

    Liebig

    22 Sep 2015

    Mercedes-Benz

    17 Sep 2015

    Office National du Tourisme Tunisien

    21 Août 2015

    Serious Game

    17 Juil 2015

    Engie

    22 Juin 2015

    UN Guiding Principles Reporting Framework

    21 Mar 2015

    Dites-le avec Nutella®

    21 Fév 2015

    HEC

    21 Déc 2014

    AREVA

    21 Déc 2014
    © 2008-2017 ITALIC™ • 8 bis rue Abel • 75012 PARIS • Tel +33 (0)1 48 44 46 35 • RCS PARIS 508 228 772 • Powered by WordPress & GoodLayers
    Nous utilisons des cookies pour vous garantir la meilleure expérience sur notre site web.
    Cookie settingsACCEPTER
    Manage consent

    Privacy Overview

    This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
    Necessary
    Toujours activé
    Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
    Non-necessary
    Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
    Enregistrer & appliquer