Introduction to shtml

Source: Internet
Author: User
Tags echo command

We recommend that you check the rewrite module and SSI (Server Side Include) of Apache ).
========================================================== ======================================
SSI Usage Details

Have you ever been or are you worried about how to modify a website containing thousands of pages in the shortest time? So you 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 an HTML file. 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 complicated functions such as shell and CGI scripts. SSI can be called the best helper for website developers who have a shortage of funds, time shortage, and heavy workload.
SSI was initially launched on the NCSA server platform and has been expanded and enhanced on Apache servers. It can now run on almost all servers. 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 file or create a. htaccess file in the directory where SSI is needed to start ssi. Specifically, the process is as follows:
1. Server Configuration File
If you have access to the server configuration file, you can edit the file access. conf and SRM. conf to start ssi.
First, use Telnet to remotely log on to the server and find the directory where the configuration file is stored. Generally, the configuration files of the Apache server are stored in the "/usr/local/etc/httpd/conf" directory. Open the SRM. conf file 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 the configuration file, but you only need to find the two lines starting with addtype and remove the '#' symbol at the beginning of each line.
Save the modification, and then open the file access. conf. You need to find the part that sets DocumentRoot in the file. Generally, the text in this section is as follows, but other settings are included between the <directory> and </directory> labels.
# This shoshould be changed to whatever you set DocumentRoot.
<Directory/usr/local/etc/httpd/htdocs>
# This may also be "NONE", "all", or any combination of "indexes ",
# "Includes", or "followsymlinks"
Options indexes followsymlinks includes
</Directory>
If you do not want to execute scripts or shell commands, you can add the keyword IncludesNOEXEC to the options Option line to allow SSI, but not CGI or script commands. (Note: the Apache server of the latest version has only one configuration file httpd. conf. All the above mentioned content has been included in this file)
2. Create a file. htaccess
If you cannot directly access the server configuration file, you can use the file editor to create a file named. htaccess. Note that the file name must be preceded by the symbol "." so that the server can know that the file is a hidden file, which improves the file security and avoids incorrect operations. Add the following three lines of text to the. htaccess file:
Options indexes followsymlinks includes
Addtype application/X-httpd-CGI. cgi
Addtype text/X-server-parsed-html. shtml
After that, you can upload the. htaccess file to the corresponding directory on the server. This file is valid for all subdirectories. 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 file.
3.use .shtmlor .html?
Any file 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. Hosts file. On the other hand, if ssiis is used for multiple pages, but the suffix of .shtml is not expected by the user, 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 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.
All SSI commands use "<! -- # "Start, where" <! -"And" # "cannot have any space between them. Otherwise, the server treats the SSI command as a normal file comment and does not display any results or generate error messages. In addition, there cannot be spaces on both sides of the "=" in the SSI command. The value on the right must be included in double quotation marks, followed by spaces, and the end tag "--> ".
The SSI command contains six types of commands and their respective parameters, as shown in the following code:
Directives Parameters
Config errmsg, timefmt, sizefmt
Include virtual, file
Echo VaR
Fsize File
Flastmod File
Exec cmd, CGI
Next we will introduce them one by one.
1. config command
The Config command is mainly used to modify the default settings of SSI. Where:
Errmsg: sets the default error message. To return user-defined error messages normally, the errmsg parameter in the HTML file must be placed before other SSI commands; otherwise, the client can only display default error messages, instead of user-defined information.
<! -- # Config errmsg = "error! Please email webmaster@mydomain.com -->
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.
Format description instance
%
% A the abbreviation of Thu seven days a week
% A seven days a week Thursday
% B-month abbreviation form APR
% B April
% D the day of the month 13
% D mm/DD/yy Date Format 04/13/00
% H hour (in 24-hour format, from 00 to 23) 01
% I hour (12-hour format, from 00 to 11) 01
% J the day of the year, from 01 to 365 104
% M the month of the year, from 01 to 12 04
% M minutes in an hour, from 00 to 59 10
% P am or PM AM
Local time in the 12-hour format of % R, in the format of 01:10:18 AM
% I: % m: % s am | pm
% S the second in a minute, from 00 to 59 18
% T in 24-hour format % H: % m: % s 01:10:18
% U the week of the year, from 00 to 15
52. take Sunday as the day of every week
Day 1
% W the first day of a week, from 0 to 6 4
% W the week of the year, from 00 15
To 53, with Monday as every week
The first day
% Y, abbreviated form from 00 to 99 00
% Y represents 2000 a year in four digits
% Z Time Zone name MDT
Sizefmt: determines whether the file size is expressed in bytes, kilobytes, or megabytes. In bytes, the parameter value is "bytes". You can use the abbreviations 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 parsed documents, which is the key to the whole ssi. By using the include command, you only need to change one file 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" -->
To organize site content more rationally, you can create the "des" subdirectory under the root directory to store all the contained files. 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 all the files contained in HTML documents in one directory, and store different pages in different directories or subdirectories according to their relationships. No matter which document is parsed by the server, you can find the contained file 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 file, it is not flexible. When you encounter such a problem, you can use two files that contain the title tag, one for the content before the title tag, and the other for the part after the meta tag, you can add any custom content between two contained 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 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? You can save the included files with the suffix ".html" so that you can call other included files in the included files.
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 file. 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 files. For example, if we don't want a person who is not familiar with HTML to directly modify the news page on the website, we can just ask him to update a separate text file, then, the file will be included in the hmtl document, so that the original page will not be damaged and the content will be updated at the same time.
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:
Index.html
Document_uri: displays the virtual path of the current document. For example:
<! -- # Echo Var = "document_uri" -->
The result is as follows:
/Yourdirectory/yourfilename.html
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. All special characters are 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: similar to date_local, but returns a date based on 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 feature of SSI. You only need to add the following simple lines of text to the HTML document to dynamically display the Update Time on the page.
<! -- # Echo Var = "last_modified" -->
CGI Environment Variable
In addition to SSI environment variables, the echo command can also display 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 file. You can customize the output format based on the sizefmt parameter of the config command.
<! -- # Fsize file = "index_working.html" -->
5. flastmod: displays the last modification date of the specified file. You can control the output format using the timefmt parameter of the config command.
<! -- # 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 dates of all links 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 that the purpose of using flastmod to display the date of modification.
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 on the server is used to place a counter on each page:
<! -- # Exec CGI = "/cgi-bin/counter. pl" -->

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.