SSI Usage details (Turn one)

Source: Internet
Author: User
Tags date format command line config file size include time and date access
Have you ever been or are you in the shortest time possible to complete a site containing thousands of pages of the changes and distress? Then you can look at the introduction of this article, may be able to help you.

What is SSI?

SSI is the abbreviation of English server Side includes, translated into Chinese is the meaning that server side contains. Technically, an SSI is a command or pointer that can be invoked through a comment line in an HTML file. SSI is powerful, with a simple SSI command that enables content updates across the Web, dynamically displaying time and date, and performing complex functions such as shell and CGI scripts. SSI can be called the best helper for Web developers who are short of cash, tense, and have a lot of work.

SSI was originally launched on the NCSA server platform, expanded and enhanced in the Apache server, and is now ready to run on almost any server. This article will mainly combine the Apache server to introduce the use of SSI.


How do I start SSI?

Under the Apache server, you can start SSI by directly editing the server configuration file or by creating a. htaccess file in a directory that needs to use SSI. Specifically, the process is as follows:


1. Server configuration file

If the user has access to the server configuration file, you can start the SSI by editing the files access.conf and srm.conf.

First use Telnet to telnet to the server and locate the directory where the configuration file resides. In general, the Apache server configuration files are stored in the "/usr/local/etc/httpd/conf" directory. Using any type of text editor to open file srm.conf, locate the following lines:

# If you are want to use server side includes, or CGI outside
# scriptaliased Directories, uncomment the following lines.
#AddType text/x-server-parsed-html. shtml

#AddType application/x-httpd-cgi. Cgi

The user's profile may not have the above comment instruction line, but just find two lines starting with AddType and remove the "#" symbol at the front of each line.

Save the changes, and then open the file access.conf. The user needs to find the part of the file that sets the DocumentRoot (root file). Generally, the text of the paragraph is as follows, but it does not exclude other settings between the <Directory> and </Directory> tags.

# This should is changed to whatever your set DocumentRoot to.
<Directory/usr/local/etc/httpd/htdocs>
# This may also is ' None ', ' all ', or any combination of ' Indexes ',
# "Includes", or "followsymlinks"
Options Indexes followsymlinks Includes
</Directory>

If the user does not want to execute a script or shell command, you can include the keyword includesnoexec in the options option line, which allows SSI, but cannot execute CGI or script commands. (Note: The latest version of the Apache server has only one profile httpd.conf, and the above mentioned content has been included in the file)

2. Create a file. htaccess

If the user does not have direct access to the server configuration file, you can use the file editor to create a file named. htaccess. Note that you must have a symbol "." Before the file name so that the server can know that the file is a hidden file, thereby improving the security of the file and avoiding the wrong operation. The following three lines of text need to be added to the. htaccess file:

Options Indexes followsymlinks Includes
AddType application/x-httpd-cgi. Cgi
AddType text/x-server-parsed-html. shtml

When you are done, you can upload the. htaccess file to the appropriate directory on the server, which is valid for all subdirectories. If the user wants to ban CGI or shell commands at the directory level, you can add keyword includesnoexec to the options option line in the. htaccess file.

3. Use of. shtml or. html?

Any file that contains SSI must undergo the server parsing process before uploading to the client. Although this will increase the load on the server to some extent, the performance of a server will not decrease significantly unless the user's site has millions of users per day. However, if you don't need to use SSI on every page, it's really not necessary to have the server parse every page. If the user only wants to use SSI on several special pages, you can change the file's suffix name to. shtml so that the server can resolve only. shtml files that contain SSI. On the other hand, if you have multiple pages using SSI, but users do not want to use the. shtml suffix name, you can use the following command line in the. htaccess file:

AddType text/x-server-parsed-html. html


SSI syntax

SSI follows the following format when used:

<!--#directive parameter= "value"-->

The directive is the instruction name sent to the server, parameter is the object of instruction, and value is the result of the command processing that the user wants.
All SSI commands start with "<!--#", where there is no space between "<!-" and "#", otherwise the server will treat SSI commands as normal file annotations without displaying any results or error prompts. In addition, there can be no spaces on either side of the "=" in the SSI command, and the value on the right must be enclosed in double quotes, followed by a space, and finally the end tag "-->".

The SSI command contains six classes of instructions and their respective parameters, as follows:


Directives
Parameters

Config
ErrMsg, TIMEFMT, sizefmt

Include
Virtual, file

Echo
Var

Fsize
File

Flastmod
File

Exec
CMD, CGI



Here we will introduce each of them.


1.Config command

The config command is primarily used to modify the default settings for SSI. which

ErrMsg: Sets the default error message. In order to return the user-defined error message normally, the errmsg parameter must be placed in front of the other SSI commands in the HTML file, otherwise the client can only display the default error message, not the custom information set by the user.

<!--#config errmsg= "error! Please email webmaster@mydomain.com-->

TIMEFMT: Defines the use format for dates and times. The TIMEFMT parameter must be used before the echo command.

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

<!--#echo var= "last_modified"-->

Display results as:

Wednesday, April 12, 2000

Perhaps the user is unfamiliar with the%a%B%d used in the previous example, so let's summarize some of the more commonly used date and time formats in SSI in tabular form.

Format
Description
Instance

%%
%
 
%a
Abbreviated form for seven days a week
Thu

%A
Seven days a week
Thursday

%b
Abbreviated form of the month
Apr

%B
Month
April

%d
The first day of one months
13

%d
Mm/dd/yy Date format
04/13/00

%H
Hours (24-hour system, from 00 to 23)
01

%I
Hours (12-hour system, from 00 to 11)
01

%j
The first days of the year, from 01 to 365
104

%m
The first few months of the year, from 01 to 12
04

%m
The first few minutes of the hour, from 00 to 59.
10

%p
AM or PM
Am

%r
12-hour local time, formatted as%i:%m:%s AM | Pm
01:10:18 AM

%s
The first few seconds in a minute, from 00 to 59.
18

%T
24-hour%h:%m:%s time format
01:10:18

%u
A few weeks in a year, from 00 to 52, to Sunday as the first day of the week
15

%w
The first day of the week, from 0 to 6
4

%w
A few weeks in a year, from 00 to 53, to Monday as the first day of the week
15

%y
The abbreviated form of the year, from 00 to 99
00

%Y
Use four digits to indicate a year
2000

%Z
Time Zone Name
Mdt



SIZEFMT: Determines whether the file size is expressed in bytes, kilobytes, or megabytes. If the parameter value is "bytes" in bytes, the abbreviation can be used for kilobytes and megabytes. Similarly, the SIZEFMT parameter must be placed in front of the fsize command before it can be used.

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

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


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: info-contact@alibabacloud.com 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.