SSI Usage Details

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

Have you ever been or are you worried about how you can complete changes to a site that contains thousands of pages in the shortest amount of time? 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 ',
Options Indexes followsymlinks Includes
</Directory>

If the user does not want to execute a script or shell command, you can add a keyword includesnoexec to 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. Notice that the filename must have a symbol "." So that the server can know that the file is a hidden file, thereby improving the security of the file, avoid error 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, add the 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 every 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 extraordinary pages, the file's suffix name can be changed 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 "<!

2.Include command

The Include command inserts text or pictures from other documents into the currently parsed document, which is the key to the entire SSI. You can update the entire site in an instant by simply changing one file with the Include command!

Include command with two different parameters, if the use of incorrect parameters to update the site, not only to achieve the original intention, but will get a lot of error messages.

Virtual: gives a dummy path to a document on the server side. For example:

<!--#include virtual= "/includes/header.html"-->

For a more reasonable organization of the content of the site, users can create includes subdirectories under the root directory to hold all the included files. The virtual parameter notifies the server that it is going to contain a dummy file, that is, that the file is not in the same directory as the document currently being parsed, but is stored in a different directory. Depending on the value of the parameter, the server finds the includes subdirectory under the root directory. With this method, the user can put all the files contained in the HTML document in a directory, and according to the relationship between the different pages stored in different directories or subdirectories. No matter what document the server resolves to find the included file, no error occurs.

But here's a little problem to solve. In general, we will add some title and meta tags to the page, if we stipulate that all pages call the same header file, it is very inflexible. When a user encounters a problem like this, you can use two include files, one before the title tag, the other after the meta tag, and you can add any custom content between the two included files. For example:

<!--#include virtual= "/includes/header1.html"-->
<title>your Page title</title>
<link rel = STYLESHEET href = "Http://domain.com/styles/my.css" Type = "Text/css" >
<meta NAME = "Description" CONTENT = "Description of page" >
<meta NAME = "Keywords" CONTENT = "Keywords for page" >
<!--#include virtual= "/includes/header2.html"-->

Place page Content here

<!--#include virtual= "/includes/footer.html"-->

From the above we can see that by including headers and footers in the page, you can significantly reduce the amount of site updates. But what if we want to dynamically display some content, such as the last time the page is updated? No problem, we can save the containing file using the. html suffix so that other include files can be invoked in the include file.

File: here? The relative path of the current directory, where the "..." cannot be used. /"And you cannot use absolute paths. For example:

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

This requires a header.html file to be included in each directory. Of course, using this method is not much simpler than updating each page, but it is convenient if users update only one or two files. For example, if we do not want a person unfamiliar with HTML to directly change the news page in the site, you can just let him update a separate text file, and then include the file in the HMTL document, so that will not destroy the original page, but also updated the contents of the two worlds.


3.Echo:

The echo command can display the following environment variables:

Document_name: Displays the name of the current document.

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

Display results as:

Index.html

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

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

Display results as:

/yourdirectory/yourfilename.html

With the development of the Web site, the increasingly long URL address will certainly make people headache. If you use SSI, everything will be solved. Because we can combine the domain name of the website with the SSI command to display the complete URL, namely:

http://yourdomain<!--#echo var= "Document_uri"-->

Query_string_unescaped: Displays the query string sent by the client without escaping processing, where all the extraordinary characters are preceded by an escape character "". For example:

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

Date_local: Displays the date and time the server set the time zone. The user can combine the timefmt parameters 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"-->

Display results as:

Saturday, the April, in the year 2000
DATE_GMT: The function is the same as date_local, except that it returns a date based on Greenwich Mean time. For example:

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

Last_modified: Displays the last update time for the current document. Again, this is the very real Mary 龉 δ Fascine in SSI?

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.