SSI use details
Have you ever done in how you can 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, the SSI can be launched 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: # if you want to use server side incrudes, or cgi outside # scriptaliased directories, uncomment the following lines. # Addtype text / x-server-parse HTML.SHTML # addtype application / x-httpd-cgi .cgi may not have the above note instruction line, but simply 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. It is generally said that the text is as follows, but it does not exclude the
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: Options indexes backsymlinks includedtype application / x-httpd-cgi .cgiadtype text / x-server-pased-html .shtml can then upload the .htaccess file to the corresponding directory of the server, This file 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 plurality of pages that use SSI, but the user does not want to use .SHTML's suffix name, you can use the following command line in .htaccess file: addtype text / x-server-pased-html .htmlssi syntax SSI Follow the following format: where Directive is the instruction name sent to the server, parameter is the operation object of the instruction, and the value is the instruction processing result of the user wants. . All SSI commands start with "". The SSI command contains six types of instructions and their respective parameters, as follows: DirectiveSParametersconfig errmsg, timefmt, sizefmtincludevirtual, fileechovarfsizefileflastmodfileexecmmd, 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. Where: errmsg: Sets 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: Define the date and time of the time pattern. Timefmt parameter must be used before the echo command.
display result is: Wednesday, April 12, 2000 maybe user The% a% B% D used in the above example is very unfamiliar. Below we will summarize some of the commonly used date and time format in the SSI in the form of a table. Format Description Instance %%%% A week's abbreviation Form THU% A For a week. THURSDAY% B Month Abbreviation Form APR% B April% D 1 month 13% DMM / DD / YY Date Format 04 / 13/00% H hours (24-hour system, from 00 to 23) 01% i hour (12-hour system, from 00 to 11) 01% J, from 01 to 365104% m within one year For a few months, from 01 to 1204% M: from 00 to 5910% PAM or PMAM% R12 small local time, format% i:% m:% S am | PM01: 10: 18 AM% S for the first few seconds, from 00 to 5918% T24 hourly-made% h:% m:% s time format 01: 10: 18% u 10 months, from 00 to 52 In Sunday, as the first day of each week, the first day of each week, from 0 to 64% W, from 00 to 53, as a week in Monday as each week The abbreviation of 15% y years, from 00 to 9900% Y, four digits indicate a year 2000% z time zone name MDT SIZEFMT: Decision file size is byte, kiloby, 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.
The 2.include command The include command can put 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. For example: In order to more reasonable organizational sites, users can create an incutes 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. For example:
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: echo command can display the following environment variables: Document_name: Displays the name of the current document. The result is: index.html document_uri: Displays the virtual path of the current document. For example: The result is: /yirateDirectory/yourfilename.html With the continuous development of the website, 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 complete URL, ie: http:// youriMain query_string_unescaped: Show uncontrolled processed by customers The query string sent by the end, where all of the special characters have escape characters "/". For example: 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. For example: The 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 standard time. For example: 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. For example: Server_name: Displays the host name, DNS alias or IP address of the server. For example: Server_Protocol: Displays the protocol name and version used by the client request, such as HTTP / 1.0.
For example: Server_port: Displays the server's response port. For example: Request_method: Displays the client's document request method, including get, head, and post. For example: 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 combined 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 FlastMod The parameter shows the update date of all links on a page. The method is as follows: file Another file display result For: File April 19, 2000another File January 08, 2000 maybe some readers will think that both links are so complicated, and it is not convenient little. 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. The 6.EXECEXEC command can perform 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.