Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Server Side Includes
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Directives == === Common === The following are SSI directives from the times of [[NCSA HTTPd]] (the 1990s).<ref name="ncsa-ssi">{{cite web |title=Server Side Includes (SSI) |url=http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html |website=NCSA HTTPd Tutorial |access-date=24 March 2019 |archive-url=https://web.archive.org/web/19970303194503/http://hoohoo.ncsa.uiuc.edu/docs/tutorials/includes.html |archive-date=3 March 1997|url-status=dead}}</ref> Some implementations do not support all of them.<ref name=nginx-ssi>{{cite web |title=Module ngx_http_ssi_module |url=http://nginx.org/en/docs/http/ngx_http_ssi_module.html |website=nginx documentation |access-date=16 November 2021}}</ref> {| class="wikitable" |+NCSA HTTPd SSI directives |- ! Directive ! Parameters ! Description ! Example |- | <code>include</code> | file or virtual | This is probably the most used SSI directive. It allows the content of one document to be [[Transclusion|transcluded]] in another. The included document can itself be another SSI-enabled file. The <code>file</code> or <code>virtual</code> parameters specify the file ([[HTML]] page, text file, script, etc.) to be included. NCSA HTTPd did not support [[Common Gateway Interface|CGI]] via <code>include</code>,<ref name="ncsa-ssi"/> but later Apache HTTPd does.<ref name="apache-httpd-doc-mod-include">{{cite web | url = http://httpd.apache.org/docs/current/mod/mod_include.html#element.include | title = Apache Module mod_include | work = Apache HTTP Server Version 2.4 Documentation | publisher = Apache Software Foundation | access-date = 2021-09-07 }}</ref> If the process does not have access to read the file or execute the script, the include will fail. The parameter "<code>virtual</code>" handles any directory paths as if part of the URL, while "<code>file</code>" handles any directory paths as in the underlying filesystem. When using "<code>file</code>" it is forbidden to reference absolute paths or <code>../</code> to access a parent directory. The Apache documentation recommends using "<code>virtual</code>" in preference to "<code>file</code>".<ref name="apache-httpd-doc-mod-include"/> | <pre style="white-space:pre"><nowiki> <!--#include virtual="menu.cgi" --> <!--#include file="footer.html" --></nowiki></pre> |- | <code>exec</code> | cgi or cmd | This directive executes a program, script, or shell command on the server. The cmd parameter specifies a server-side command; the cgi parameter specifies the path to a [[Common Gateway Interface|CGI]] script. {{cns|date=September 2021|The <code>PATH_INFO</code> and <code>QUERY_STRING</code> of the current SSI script will be passed to the CGI script, as a result "exec cgi" should be used instead of "include virtual".}} | <pre style="white-space:pre"><nowiki> <!--#exec cgi="/cgi-bin/foo.cgi" --> <!--#exec cmd="ls -l" --></nowiki></pre> |- | <code>echo</code> | var | This directive displays the contents of a specified [[HTTP]] [[environment variable]]. {{cns|date=September 2021|Variables include <code>HTTP_USER_AGENT</code>, <code>LAST_MODIFIED</code>, and <code>HTTP_ACCEPT</code>.}} | <pre style="white-space:pre"><nowiki>Your IP address is: <!--#echo var="REMOTE_ADDR" --></nowiki></pre> |- | <code>config</code> | timefmt, sizefmt, or errmsg | This directive configures the display formats for the date, time, filesize, and error message (returned when an SSI command fails). | <pre style="white-space:pre"><nowiki><!--#config timefmt="%y %m %d" --> <!--#config sizefmt="bytes" --> <!--#config errmsg="SSI command failed!" --></nowiki></pre> |- | <code>flastmod</code> and <code>fsize</code> | file or virtual | These directives display the date when the specified document was last modified, or the specified document's size. The file or virtual parameters specify the document to use. The file parameter defines the document as relative to the document path; the virtual parameter defines the document as relative to the document root. | <pre style="white-space:pre"><nowiki><!--#flastmod virtual="index.html" --> <!--#fsize file="script.pl" --></nowiki></pre> |} === Control directives === Control directives are later added to SSI. They include the ubiquitous if-elif-else-endif flow control and variable writing as well as more exotic features like loops only found in some implementations. {| class="wikitable" |- ! Directive ! Parameters ! Description ! Example ! Found in |- | {{plainlist| * if * elif * else * endif }} | expr | The [[if statement]]. Used for condition tests that may determine and generate multiple logical pages from one single physical page. <code>elif</code> is a shorthand for nested else-if. <code>else</code> and <code>endif</code> do not accept parameters. Expression syntax vary among implementations. Variable existence and equality/regex checks are commonly supported. Jigsaw uses expressions split over multiple attributes instead.<ref name=jig/> | <pre style="white-space:pre"><nowiki> <!--#if expr="${Sec_Nav}" --> <!--#include virtual="secondary_nav.txt" --> <!--#elif expr="${Pri_Nav}" --> <!--#include virtual="primary_nav.txt" --> <!--#else --> <!--#include virtual="article.txt" --> <!--#endif --> </nowiki></pre> | Ubiquitous. |- | set | var, value | Sets the value of a SSI variable. Apache provides additional parameters for [[encoding]]s.<ref name=apache-inc/> | <pre style="white-space:pre"><nowiki><!--#set var="foo" value="bar" --></nowiki></pre> | Apache,<ref name=apache-inc>{{cite web |title=mod_include |url=https://httpd.apache.org/docs/current/mod/mod_include.html |website=Apache HTTP Server |access-date=25 March 2019}}</ref> Nginx<ref name="nginx">{{cite web |title=ngx_http_ssi_module |url=https://nginx.org/en/docs/http/ngx_http_ssi_module.html |website=nginx.org |access-date=25 March 2019}}</ref> |- | <code>printenv</code> | | This directive outputs a list of all SSI variables and their values, including environmental and user-defined variables. It has no attributes. | <pre style="white-space:pre"><nowiki><!--#printenv --></nowiki></pre> | Apache<ref name=apache-inc/> |}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)