SSI Usage Details

Source: Internet
Author: User
Tags echo command time and date

SSI Usage Details


Have you ever or are worrying about how you can modify a website containing thousands of pages in the shortest time? So I can take a look at the introduction of this article, which may be helpful to you.


What is ssi?


SSI is the abbreviation of server side encryption DES. Technically speaking, SSI is a command or pointer that can be called through the annotation line in the HTML document. SSI has powerful functions. You only need to use a simple SSI command to update the content of the entire website, dynamically display the time and date, and execute complex functions such as shell and CGI script programs. SSI can be called the best helper for website R & D personnel who are short of funds, time-consuming, and heavy-workload.


SSI was initially launched on the NCSA server platform and has been expanded and enhanced on Apache servers. It is now able to run on almost any server. This document describes how to use SSI Based on the Apache server.



How to start ssi?


On the Apache server, you can directly edit the server configuration document or create a. htaccess document in the directory where SSI is needed to start ssi. Specifically, the process is as follows:



1. server configuration document


If you have access to the server configuration document, you can start ssi by editing the document access. conf and SRM. conf.


First, use Telnet to remotely log on to the server and find the directory where the configuration document is stored. Generally, configuration documents of the Apache server are stored in the "/usr/local/etc/httpd/conf" directory. Open the document SRM. conf in any text editor and find the following lines:


# If you want to use server side except des, or CGI outside

# Scriptaliased directories, uncomment the following lines.

# Addtype text/X-server-parsed-html. shtml


# Addtype application/X-httpd-CGI. cgi


The preceding annotation command line may not exist in your configuration document, but you only need to find the two lines starting with addtype and remove the "#" symbol at the beginning of each line.


Save the changes, and then open the document access. conf. You need to find the configuration DocumentRoot section in the document. Generally, the text of this section is as follows, but other configuration content is included between the <directory> and </directory> labels.


# This shoshould be changed to whatever you set DocumentRoot.


# This may also be "NONE", "all", or any combination of "indexes ",

# "Includes", or "followsymlinks"

Options indexes followsymlinks includes



If you do not want to execute a script or shell command, you can add the keyword IncludesNOEXEC to the options Option line to allow SSI, but cannot execute CGI or script commands. (Note: the latest version of Apache server has only one configuration file httpd. conf. All the above mentioned content has been included in this document)


2. Create document. htaccess


If you cannot directly access the server configuration document, you can use the document editor to create a document named. htaccess. Note that the document name must be preceded by the "." symbol, so that the server can know that the document is a hidden document, so as to improve the security of the document and avoid wrong operations. Add the following three lines of text to the. htaccess document:


Options indexes followsymlinks includes

Addtype application/X-httpd-CGI. cgi

Addtype text/X-server-parsed-html. shtml


After that, you can upload the. htaccess document to the corresponding directory on the server. This document is valid for any subdirectory. If you want to disable CGI or shell commands at the directory level, you can add the keyword IncludesNOEXEC to the options Option line in the. htaccess document.


3.use .shtmlor .html?


Any document containing SSI must go through the parsing process of the server before it is uploaded to the client. Although the server load is increased to some extent, the performance of a server will not decrease unless the user's website has millions of users accessing it every day. However, if you do not need to use SSI on every page, there is indeed no need for the server to parse every page. Documentation. The following command line can be used in the. htaccess document if ssiis used on multiple pages but the user does not want to use the suffix of .shtml:


Addtype text/X-server-parsed-html. html



SSI syntax


SSI follows the following format during use:


<! -- # Directive Parameter = "value" -->


Specifically, Directive is the command name sent to the server, parameter is the operation object of the command, and value is the command processing result that the user wants.

Any SSI command is "<! -- # "Start, where" <! -There is no space between "and" # ". Otherwise, the server treats the SSI command as a normal document comment and does not display any results or generate error messages. In addition, the "=" in the SSI command cannot have spaces on both sides. The value on the right must be included in double quotation marks, followed by spaces, and finally the end tag "--> ".


The SSI command contains six types of commands along with their respective parameters, as shown in the following code:







Errmsg, timefmt, sizefmt



Virtual, file















Next we will introduce them one by one.



1. config command


The Config command is mainly used to modify the default configurations of SSI. Where:


Errmsg: configure the default error message. To return user-defined error messages normally, the errmsg parameter must be placed before other SSI commands in the HTML document. Otherwise, the client can only display the default error messages, instead of user-defined information.


<! -- # Config errmsg = "error! Please email -->


Timefmt: defines the format of the date and time. The timefmt parameter must be used before the echo command.


<! -- # Config timefmt = "% A, % B % d, % Y" -->


<! -- # Echo Var = "last_modified" -->


The result is as follows:


Wednesday, 10000l 12,200 0


Maybe the user is unfamiliar with % A % B % d in the previous example. Below we will summarize some of the commonly used Date and Time formats in SSI in the form of a table.









Seven days a week




Seven days a week



% B

Abbreviated form of month



% B


Else l


% D

The day of the month.



% D

Mm/DD/yy Date Format



% H

Hour (in 24-hour format, from 00 to 23)



% I

Hour (in 12-hour format, from 00 to 11)



% J

The day of the year, from 01 to 365



% M

The number of months in a year, from 01 to 12



% M

Minutes in an hour, from 00 to 59



% P

AM or PM



% R

Local time in 12-hour format: % I: % m: % s am | pm

01:10:18 AM


% S

The second in a minute, from 00 to 59.



% T

% H: % m: % s time format in the 24-hour format



% U

The week number of a year, from 00 to 52, takes Sunday as the first day of each week.



% W

The first day of a week, from 0 to 6



% W

The week number of a year, from 00 to 53, with Monday as the first day of each week



% Y

The abbreviation of the year, from 00 to 99



% Y

A year is represented by four digits.



% Z

Time zone name




Sizefmt: determines whether the document size is expressed in bytes, kilobytes, or megabytes. In bytes, the parameter value is "bytes". The abbreviations can be used for kilobytes and megabytes. Similarly, the sizefmt parameter must be placed before the fsize command.


<! -- # Config sizefmt = "bytes" -->


<! -- # Fsize file = "index.html" -->


2. include command


The include command inserts text or images from other documents into the currently parsed documents, which is the key to the whole ssi. By using the include command, you only need to change one document to instantly update the entire site!


The include command has two different parameters. If an incorrect parameter is used to update the site, not only does not meet the original intention, but will get a lot of error information.


Virtual: the virtual path to a document on the server. For example:


<! -- # Include virtual = "/Includes/header.html" -->


In order to organize site content more rationally, you can create the des sub-directory under the root directory to store any containing documents. The virtual parameter notifies the server that it contains a virtual file, that is, the file and the file being parsed are not in the same directory, but stored in other directories. The server finds the des sub-directory under the root directory based on the value of this parameter. In this way, you can put any HTML document in a directory, and store different pages in different directories or subdirectories based on their relationships. No matter which document is parsed by the server, the contained document can be found without any errors.


However, there is a small problem to solve. Generally, we add some title and meta tags to the page. If we require that all pages call the same header document, it is not flexible. When a user encounters such a problem, he can use two documents, one for configuring the content before the title tag and the other for configuring the meta tag, you can add any custom content between two contained documents. For example:


<! -- # Include virtual = "/Includes/header1.html" -->

<Title> your page title </title>

<LINK rel = stylesheet href = "" type = "text/CSS">

<Meta name = "Description" content = "Description of page">

<Meta name = "keywords" content = "keywords for page">

<! -- # Include virtual = "/Includes/header2.html" -->


Place the page content here


<! -- # Include virtual = "/Includes/footer.html" -->


We can see that adding headers and footers to a page can greatly reduce the workload of site updates. But what if we want to dynamically display some content, such as the last update time of the page? Without questions, we can save the included documents with the suffix ".html" so that we can call other included documents in the included documents.


File: Specifies the relative path to the current directory. "../" cannot be used or an absolute path. For example:


<! -- # Include file = "header.html" -->


In this case, each directory contains a header.html document. Of course, using this method is not much easier than updating each page, but it is very convenient if you only update one or two documents. For example, if we don't want a person who is not familiar with HTML to directly change the news page on the website, we can only let him update a separate text document, this document is then included in the hmtl document, so that the original page will not be damaged, and the content is updated at the same time, the best of both worlds.



3. Echo:


The echo command displays the following environment variables:


Document_name: displays the name of the current document.


<! -- # Echo Var = "document_name" -->


The result is as follows:




Document_uri: displays the virtual path of the current document. For example:


<! -- # Echo Var = "document_uri" -->


The result is as follows:




With the continuous development of websites, those longer and longer URLs will be a headache. If SSI is used, everything will be solved. Because we can combine the website domain name with the SSI command to display the complete URL, that is:


Http: // yourdomain <! -- # Echo Var = "document_uri" -->


Query_string_unescaped: displays unescaped query strings sent by the client. Any special character must be preceded by the Escape Character "\". For example:


<! -- # Echo Var = "query_string_unescaped" -->


Date_local: displays the date and time when the server sets the time zone. You can combine the timefmt parameter of the config command to customize the output information. For example:


<! -- # Config timefmt = "% A, the % d of % B, in the year % Y" -->

<! -- # Echo Var = "date_local" -->


The result is as follows:


Saturday, the 15 of each l, in the year 2000


Date_gmt: The function is the same as that of date_local, but the returned date is based on the Greenwich Mean Time. For example:


<! -- # Echo Var = "date_gmt" -->


Last_modified: displays the Last Update Time of the current document. Similarly, this is a very practical function in SSI. As long as you add the following simple lines of text to the HTML document, you can dynamically display the Update Time on the page.


<! -- # Echo Var = "last_modified" -->



CGI Environment Variable


In addition to SSI environment variables, the echo command also displays the following CGI Environment variables:


Server_software: displays the name and version of the server software. For example:


<! -- # Echo Var = "server_software" -->


SERVER_NAME: displays the host name, DNS alias, or IP address of the server. For example:


<! -- # Echo Var = "SERVER_NAME" -->


Server_protocol: displays the protocol name and version used by the client request, such as HTTP/1.0. For example:


<! -- # Echo Var = "server_protocol" -->


Server_port: display the server's response port. For example:


<! -- # Echo Var = "server_port" -->


Request_method: display the client's document request methods, including get, Head, and post. For example:


<! -- # Echo Var = "request_method" -->


Remote_host: the name of the client host that sends the request information.


<! -- # Echo Var = "remote_host" -->


Remote_addr: displays the IP address of the client sending the request.


<! -- # Echo Var = "remote_addr" -->


Auth_type: shows the authentication method for user identity.


<! -- # Echo Var = "auth_type" -->


Remote_user: displays the account name used by the user accessing the protected page.


<! -- # Echo Var = "remote_user" -->



4. fsize: displays the size of the specified document. The output format can be customized based on the sizefmt parameter of the config command.


<! -- # Fsize file = "index_working.html" -->


5. flastmod: displays the last modification date of the specified document. It can be used with the timefmt parameter of the config command to control the output format.


<! -- # Config timefmt = "% A, the % d of % B, in the year % Y" -->

<! -- # Flastmod file = "file.html" -->


Here, we can use the flastmod parameter to display the update date of any link page on a page. The method is as follows:


<! -- # Config timefmt = "% B % d, % Y" -->

<A href = "/directory/file.html"> file </a>

<! -- # Flastmod virtual = "/directory/file.html" -->

<A href = "/another_directory/another_file.html"> another file </a>

<! -- # Flastmod virtual = "/another_directory/another_file.html" -->


The result is as follows:


File Transfer l 19,200 0

Another file January 08,200 0


Some readers may think that the two links are so complicated and inconvenient at all. In fact, if there are 20 or more links on the page, and each link is updated on a regular basis, we can see the effect of using flastmod to display the modification date.



6. Exec


The exec command can execute CGI scripts or shell commands. The usage is as follows:


CMD: run the specified string using/bin/sh. If SSI uses the IncludesNOEXEC option, the command will be blocked.


CGI: it can be used to execute CGI scripts. For example, in the following example, the counter. pl script under the cgi-bin directory of the server is used to place a counter on each page:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.