- SHTML Have you ever done to complete the changes to a website containing thousands of pages in the shortest time? So you can look at this article, perhaps you can help you.
What is SSI?
SSI is the abbreviation of English Server Side Includes, translated into Chinese is the meaning of the server side. From a technical point of view, SSI is an HTML file, which can be called or pointers through the comment line. SSI has a powerful feature, as long as a simple SSI command can realize the content update, dynamic display time and date of the entire website, and perform complex features such as Shell and CGI scripts. SSI can be said to be the best helper for website developers who have a shortage of funds, time, and workload.
SSI is initially launched on the NCSA server platform, which is expanded and enhanced in the Apache server, which is now running on almost all servers. This article will mainly bind to the APACHE server to introduce the use of SSI.
How to start SSI?
Under the Apache server, you can create a .htaccess file to start SSI by direct editing the server profile or in a directory you need to use the SSI. Specifically, the process is as follows:
1. Server profile
If the user has access to the server profile, you can start SSI by editing file access.conf and srm.conf.
First use the Telnet remote login server to find the storage directory of the configuration file. In general, the configuration file of the Apache server is saved in the / usr / local / etc / httpd / confal directory. Use any text editor to open the file SRM.CONF, find the following lines:
# I i i u ue s u p p d d d....
#Addtype application / x-httpd-cgi .cgi
There may be no such annotation instruction lines in the user's configuration file, but as long as you find two rows starting with ADDTYPE and remove the "#" symbol of each row.
Save the modifications made, then open the file access.conf. Users need to find some of the part of setting the DocumentRoot (root file) in the file. Generally, the text is as follows, but the other settings are also included in the non-exclude and tags.
# This kind be changing to whatver you set documentroot to.
# This may also be "none", "all", or any combination of "indexes", # "incrudes", or "backsymlinks" options INDEXES FOLLOWSYMLINKS INCLUDES
If the user does not want to execute the script or shell command, you can add keyword INCLUDESNOEXEC in the Options option row, which allows SSI, but cannot perform CGI or script commands. (Note: The latest version of the Apache server has only one configuration file httpd.conf, and the content mentioned above has been included in this file)
2. Create a file .htaccess
If the user can't access the server profile directly, you can create a file called .htaccess file using the file editor. Note that the file name must have a symbol "." So the server can know that the file is hidden file, thereby increasing the security of the file, avoiding error operations. In the .htaccess file, you need to add the following three lines of text: Options Indexes Followsymlinks include addtype application / x-httpd-cgi .cgi addtype text / x-server-pased-html .shtml
After completion, you can upload the .htaccess file to the corresponding directory of the server, which is valid for all subdirectories. If the user wants to disable the CGI or shell command on the directory level, you can add keyword incrudesnoexec on the .htaccess file.
3. Use .shtml or .html?
Any file containing SSI must pass the server's parsing process before it is submitted to the client. Although a server's load is increased to some extent, the performance of a server does not have a significant decline unless a user's website has millions of access users every day. However, if it is not necessary to use SSI in each page, it is indeed necessary to let the server parses each page. If the user only wants to use SSI to use SSI in several special pages, you can change the file's suffix name to .shtml, so that the server can only resolve the .shtml file containing the SSI. On the other hand, if there is a multiple page using SSI, but the user does not want to use .SHTML's suffix name, you can use the following command line in the .htaccess file:
AddType text / x-server-pased-html .html
SSI syntax
SSI follows the following format when using:
Among them, Directive is the command name sent to the server. Parameter is the operation object of the instruction, and the value is the command processing result of the user desired. All SSI commands are "" ".
The SSI command contains six major classes and their respective parameters, as follows:
Directives Parameters
Config errmsg, Timefmt, Sizefmt
Include Virtual, File
echo var
FSIZE FILE
FlastMod file
EXEC CMD, CGI
Below we will introduce one by one.
1.config command
The config command is primarily used to modify the default settings of the SSI. among them:
Errmsg: Set the default error message. In order to be able to return the user setting error information, the errmsg parameter must be placed in front of the other SSI command in the HTML file, otherwise the client can only display the default error message instead of the custom information set by the user.
Timefmt: Defines the use format of the date and time. The TimeFmt parameter must be used before the echo command.
The display result is:
Wednesday, April 12, 2000
Perhaps the user is very unfamiliar with the% a% B% D used in the previous example. Here we summarize some of the more common date and time formats in the SSI in the form of a table.
Format Description Example
%%%% A week seven days of abbreviation form Thursday a week. Thursday% B Month Abbreviation Form APR% b Month April% d 13% D MM / DD / YY Date Format 04/13 / 00% h hours (24-hour system, from 00 to 23) 01% i hour (12 hours, from 00 to 11) 01% J, from 01 to 365 104% M, within the first few years In a month, from 01 to 12 04% M, from 00 to 59 10% P AM or PM% R 12 hourly system, the format is 01:10:18 AM% i:% M:% s AM | PM% S in the first minute, from 00 to 59 18% T 24 hour% h:% m:% s time format 01:10:18% u More than one year In the week, from 00 to 15 52, Sunday as the first day of each week, the first day of each week, from 0 to 6 4% W, from 00 15 to 53, As the first day of each week in Monday, the first day of the year, from 00 to 99 00% Y, used four digits to represent the annual 2000% z time zone name MDT
SIZEFMT: Deciding that the file size is indicated by bytes, kilobytes or megabytes. If in bytes, the parameter value is "BYTES"; the abbreviated form can be used for kilobytes and megabytes. Similarly, the SIZEFMT parameter must be placed in front of the fsize command.
2.include command
The include command can insert the text or image in other documents into the currently resolved document, is the key to the entire SSI. You can instantly update the entire site instantly through the incrude command.
The include command has two different parameters. If you update the site with the wrong parameter, you will not only get the original intention, but it will get a lot of error messages.
Virtual: Gives the virtual path to a document to the server. E.g:
In order to more reasonable organizational sites, users can create an incrudes subdirectory in the root directory to store all of the included files. The Virtual parameter can notify the server to include a virtual file, that is, the file and the currently parsed document are not in the same directory, but stored in other directories. The server finds the incrudes subdirectory in the root directory based on the value of this parameter. Using this method, users can put all the files contained in all HTML documents in a directory, and save different pages in different directories or subdirectories, depending on each other. Regardless of the server resolves which documentation can find the files contained without any errors.
However, there is a small problem to solve it here. Generally we join some Title and Meta tags in the page. If we specify that all pages call the same header file, it is very unflexible. When the user encounters such a problem, you can use two containing files, one settings before setting the Title tag, and the other after setting the META tag, and any custom content can be added between the two containing files. E.g:
Place the page here
From the top we can see that the workload of the site update can be greatly reduced by including headers and footers in the page. But if we want to dynamically display some content, such as what should I do if the last update time of the page is? No problem, we can save the included files using the .html suffix, so you can call other included files in the included file.
File: Give the relative path to the current directory, where "../" cannot be used, and the absolute path cannot be used. E.g:
This requires all of each directory that contains a header.html file. Of course, this method is not more simple than updating each page, but if the user updates one, the two files are still very convenient. For example, if we don't want a person who is not familiar with HTML directly to change the news page in the website, you can only update a separate text file, and then contain this file into the HMTL document, so you won't damage it. Original page, at the same time updated the content, two whole beauty. 3.echo:
The echo command can display the following environment variables:
Document_name: Displays the name of the current document.
The display result is:
INDEX.HTML
Document_uri: Displays the virtual path of the current document. E.g:
The display result is:
WeighDirectory /YourFileName.html
As the website is constantly evolving, those increasingly long URL addresses will definitely make people a distress. If you use SSI, everything will be solved. Because we can combine the domain name of the website and the SSI command to display the full URL, ie:
Http:// YourDomain
Query_string_unescaped: Displays the query string sent by the client unsubmitted by the unflied process, where all of the special characters have escape characters "/". E.g:
Date_local: Displays the date and time of the server setting time zone. The user can customize the output information in conjunction with the TIMEFMT parameters of the config command. E.g:
The display result is:
Saturday, The 15 of April, in The Year 2000
Date_gmt: The function is the same as Date_Local, but returns to the date based on the Greenwich time. E.g:
Last_Modified: Displays the last update time of the current document. Similarly, this is a very practical feature in SSI, as long as the following simple text is added to the HTML document, you can update the update time on the page.
CGI environment variable
In addition to the SSI environment variable, the echo command can also display the following CGI environment variables:
Server_software: Displays the name and version of the server software. E.g:
Server_name: Displays the host name, DNS alias or IP address of the server. E.g:
Server_Protocol: Displays the protocol name and version used by the client request, such as HTTP / 1.0. E.g:
Server_Port: Displays the response port of the server. E.g:
Request_method: Displays the client's document request method, including get, head, and post. E.g:
Remote_host: Displays the client host name that issues request information.
Remote_addr: Displays the client IP address that issues request information.
Auth_type: Displays the authentication method of the user identity.
Remote_user: Displays the account name used by the user who is accessing the protected page.
4.FSIZE: Displays the size of the specified file, which can be customized in conjunction with the SIZEFMT parameter of the config command.
5.FlastMod: Displays the final modification date of the specified file, which can combine the TIMEFMT parameter control output format of the config command.
Here, we can use the FLASTMOD parameter to display the update date of all links on a page. Methods as below:
File
Another file
The display result is:
File April 19, 2000 Another File January 08, 2000 maybe some readers will think that both links are so complicated, not convenient at all. In fact, if there are 20 or more links on the page, and each link is regularly updated, you can see the role of using FLASTMOD to display the modification date.
6.exec
The exec command can execute the CGI script or shell command. The method is as follows:
CMD: Use / bin / SH to perform the specified string. If the SSI uses the IncludeSnoExec option, the command will be blocked.
CGI: Can be used to perform the CGI script. For example, the following example uses the counter.pl scripker under the Directory of the Directory in each page to place a counter at each page: