Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

HTML static pages introduce public html files (ssi server-side instructions are explained in detail)

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Have you ever been or are you worried about how to make changes to a site with thousands of pages in the shortest possible time?

Then 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 English Server Side Includes, which translates into Chinese is the meaning contained on the server side. Technically, a SSI is a command or pointer in an HTML file that can be called through a comment line.

SSI has powerful functions, such as updating the content of the entire website, dynamically displaying time and date, and executing shell and CGI scripts by using a simple SSI command. SSI can be said to be the best helper for website developers who are short of funds, time constraints and heavy workload.

SSI was originally launched on the NCSA server platform, has been extended and enhanced in the Apache server, and now can run on almost all servers. This article will mainly introduce the use of SSI in combination with Apache server.

How do I start SSI?

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

1. Server profile

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

First, log in to the server remotely using Telnet to find the directory where the configuration files are stored.

In general, the configuration files for Apache servers are saved in the "/ usr/local/etc/httpd/conf" directory.

Open the file srm.conf using any text editor and find the following lines:

# If you 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 above comment instruction lines may not be available in the user's profile, but just find the two lines that begin with AddType and remove the "#" symbol at the beginning of each line.

Save your changes before opening the file access.conf. The user needs to find the section in the file that sets the DocumentRoot (root file). Generally speaking, the text of this paragraph is as follows, but it is not excluded that other settings are included between the and tag.

# This should be changed to whatever you set DocumentRoot to. # This may also be "None", "All", or any combination of "Indexes", # "Includes", or "FollowSymLinks" Options Indexes FollowSymLinks Includes

If the user does not want to execute a script or shell command, you can add the 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 configuration file, httpd.conf, and all the above mentioned have been included in this file)

two。 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 called .htaccess. Note that the file name must be preceded by a symbol "." so that the server can know that the file is a hidden file, so as to improve the security of the file and avoid misoperation. You need to add the following three lines 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 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 .shtml or .html?

Any file containing SSI must go through the parsing process of the server before it can be downloaded to the client.

Although this will increase the load on the server to some extent, there will be no significant decline in the performance of a server unless the user's site has millions of visitors every day.

However, if you don't need to use SSI on every page, there's really no need for the server to parse every page. If users only want to use SSI in a few special pages, you can change the suffix name of the file to .shtml so that the server can parse only .shtml files that contain SSI.

On the other hand, if you have multiple pages that use SSI, but users do not want to use the suffix name of .shtml, 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 using:

Where directive is the name of the instruction sent to the server, parameter is the operation object of the instruction, and value is the instruction processing result that the user wants.

All SSI commands are marked with "".

The SSI command contains six types 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

We will introduce them one by one below.

1.Config command

The Config command is mainly used to modify the default settings of SSI. Where:

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

Timefmt: defines the format for the use of dates and times. The Timefmt parameter must be used before the echo command.

The display results are as follows:

Wednesday, April 12, 2000

Perhaps the user is familiar with the% A% B% d used in the above example, so let's summarize some of the more common date and time formats in SSI in tabular form.

Format description example

%%%

% a the acronym for seven days a week Thu

% A Thursday seven days a week

The acronym for% b month Apr

% B month April

D the day ordinal of a month 13

% D mm/dd/yy date format 04ram 13ap00

% H hours (24 hours, from 00 to 23) 01

% I hours (12 hours, from 00 to 11) 01

% j the day ordinal of the year, from 01 to 365 104

The month ordinal of the year, from 01 to 12 04

% M the minute in an hour, from 00 to 59 10

% p AM or PM AM

% r 12-hour local time in 01:10:18 AM format

% I:%M:%S AM | PM

S the second ordinal of a minute, from 00 to 59 18

% H:%M:%S time format for T 24-hour system at 01:10:18

% U the week ordinal of the year, from 00 to 15 52, with Sunday as the first day of each week

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

% W the week ordinal of the year, from 00 15 to 53, with Monday as the first day of each week

Acronym for% y year, 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. If it is in bytes, the parameter value is "bytes"; for kilobytes and megabytes, you can use abbreviations. Similarly, the sizefmt parameter must precede the fsize command before it can be used.

2.Include command

The Include command can insert text or pictures from other documents into the currently parsed document, which is the key to the entire SSI. Through the Include command, you only need to change one file to update the entire site instantly!

The Include command has two different parameters, and if you update the site with the wrong parameters, you will get a lot of error messages instead of the original intention.

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

File: give a relative path to the current directory, where you cannot use ".. /" or an absolute path. For example:

This requires that each directory contain a header.html file.

In order to organize the content of the site more reasonably, users can create an includes subdirectory under the root directory to store all the included files. The Virtual parameter can tell the server that what is to be included is a virtual file, that is, the file and the document currently being parsed are not in the same directory, but in another directory.

The server finds the includes subdirectory under the root directory based on the value of this parameter. Using this method, users can put all the files contained in HTML documents in one directory and save different pages in different directories or subdirectories according to their relationship.

No matter which document the server parses, the included file can be found without any errors.

But there is a small problem that needs to be solved. We usually add some TITLE and META tags to our pages, which would be inflexible if we stipulate that all pages call the same header file.

When users encounter such a problem, they can use two include files, one before setting the TITLE tag, the other after setting the META tag, and any custom content can be added between the two include files. For example:

Your Page Title

Place the content of the page here

From the above, we can see that the workload of site updates can be greatly reduced by including headers and footers in the page. But what if we want to dynamically display something, such as the last update time of the page? No problem, we can save the include file with the .html suffix so that we can call other include files in the include file.

File: give a relative path to the current directory, where you cannot use ".. /" or an absolute path. For example:

This requires that each directory contain a header.html file. Of course, this approach is not much easier than updating every page, but it is convenient for users to update only one or two files. For example, if we do not want a person who is not familiar with HTML to directly change the news page on the site, we can just ask him to update a separate text file, and then include the file in the HMTL document, so that the original page will not be destroyed 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.

The display results are as follows:

Index.html

DOCUMENT_URI: displays the virtual path of the current document. For example:

The display results are as follows:

/ YourDirectory/YourFilename.html

As the site continues to grow, those longer and longer URL addresses are sure to be a headache. If you use SSI, everything will work out. Because we can combine the domain name of the website with the SSI command to display the complete URL, that is:

Http://YourDomain

QUERY_STRING_UNESCAPED: displays unescaped query strings sent by the client, where all special characters are preceded by the escape character "\". For example:

DATE_LOCAL: displays the date and time that the server sets the time zone. Users can customize the output information with the timefmt parameter of the config command. For example:

The display results are as follows:

Saturday, the 15 of 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:

LAST_MODIFIED: displays the last update time of the current document. Again, this is a very useful feature in SSI, as long as you add the following simple line of text to the HTML document, you can dynamically display 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 name and version of the protocol used by the client request, such as HTTP/1.0. For example:

SERVER_PORT: displays the response port of the server. For example:

REQUEST_METHOD: displays the client's document request methods, including GET, HEAD, and POST. For example:

REMOTE_HOST: displays the name of the client host that sent the request information.

REMOTE_ADDR: displays the IP address of the client that sent the request information.

AUTH_TYPE: displays the authentication method for the user's identity.

REMOTE_USER: displays the account name used by the user accessing the protected page.

4.Fsize:

Displays the size of the specified file, and you can customize the output format in combination with the sizefmt parameter of the config command.

5.Flastmod:

Displays the last modified date of the specified file, and the output format can be controlled in combination with the timefmt parameter of the config command.

Here, we can use the flastmod parameter to display the update date of all linked pages on a page. The methods are as follows:

File Another File

The display results are as follows:

File April 19, 2000

Another File January 08, 2000

Some readers may think that the two links are so complex and inconvenient at all. In fact, if there are 20 or more links on the page, and each link is updated regularly, you can see the effect of using flastmod to display the modification date.

6.Exec

The Exec command can execute a CGI script or a shell command. The method of use is as follows:

Cmd: executes the specified string using / bin/sh. If SSI uses the IncludesNOEXEC option, the command is blocked.

Cgi: can be used to execute CGI scripts. For example, the following example uses the counter.pl script in the server's cgi-bin directory to place a counter on each page:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report