Apache Open SSI (shtml) configuration enables HTML to support include steps

Source: Internet
Author: User
Tags parent directory relative

For a simple example, such as the following HTML file (named index.html):

<input type= ' text '/>
<input type= ' button ' value= ' Press '/>

A simple text box and a button, I now want to write the button part of the HTML in another. html file (for example, called btn.html) and then introduced into the index.html, what to do?


1. Loading SSI Module

First, you load the SSI module. Open Apache configuration file httpd.conf, this file should be already familiar, the previous article has been mentioned many times. Find such a line of LoadModule ssl_module modules/mod_ssl.so, remove the previous note (#).


2, add the required file types

Also find the following two lines of code under the httpd.conf file:

AddType text/html. shtml
Addoutputfilter INCLUDES. shtml

Remove the annotation, as with comments. Because the default file name for SSI technology is. shtml, we need to set the. shtml suffix in the configuration file and set the file type settings that need to be resolved for SSI technology as per their requirements.

For example, I'm going to use an. html file, so I can add it at the end of two lines of code, like this:

AddType text/html. shtml. html
Addoutputfilter INCLUDES. shtml. html

3, add INCLUDES

Or in the httpd.conf file, find such a line of Options Indexes followsymlinks, add INCLUDES at the back, and become like this:

Options Indexes followsymlinks INCLUDES

It is important to note that SSI can use the shell to execute commands, so this feature is dangerous, it will execute any commands included in the EXEC tag, and if your users have permission to modify the content of your Web page, it is recommended that the feature be turned off. Of course you can also add the IncludesNOEXEC parameter to turn off the EXEC function while preserving the SSI. At this point, change to: Options Indexes followsymlinks INCLUDES includesnoexec


4, restart Apache

Finally, restart the Apache must not forget, some children's shoes just started to configure Apache, often say how does not work ah, a lot of time is forgotten to reboot.


5. Practice

With this configuration we can introduce HTML files into HTML pages, such as:

<input type= ' text '/>
<!--#include virtual= "btn.html"-->

You can also use the file argument:

<input type= ' text '/>
<!--#include file= "btn.html"-->

What's the difference?

The include element can determine which files should be included by the file property or the virtual property. The file property is a path relative to the current directory, that is, cannot be an absolute path (with "/") or include "... /"The included file can be in the same level directory or its subdirectories, but not in the previous level directory. The virtual attribute may be more useful, which is a URL to the provided document that starts with "/", but must be on the same server as the provided document, which is the full path to the virtual directory on the Web site.

In layman's terms, virtual is equivalent to an absolute path (starting from the server root), while file is equivalent to a relative path (and the file is not yet in the parent directory). So the general use of virtual on the OK.



Let Apache support sHTML (SSI) configuration methods


sHTML and ASP are similar, in shtml named files, using some of the SSI instructions, as in the ASP instructions, you can write SSI instructions in the shtml file, when the client access to these shtml files, the server side will read and interpret these shtml files, Explain the SSI instructions contained in the sHTML file.

Servers using shtml speed will be slower than HTML, faster than PHP. The feature of sHTML is that it can be included in the page, and it can partially update the page inclusion. Widely used can easily solve the problem of advertising in the Web page, do not need to update a comprehensive static page. Instead, just update one of the included pages. Here's a look at the Apache resolution shtml configuration (SSI) method:

Open file, search shtml


Remove the first two lines of the #, which is as follows


If you want to configure shtml for the entire server

Search again for options Indexes FollowSymLinks


Add includes to the inside as shown below:


OK Restart Apache

Then test, build two files, actually a call header.shtml and a index.shtml

The header.shtml code is as follows:


Included in two forms: if you want to know, please find the relevant documents


Then visit:


sHTML Configuration succeeded ... It's good, it's strong.

Next, if not the global configuration, but the site configuration. Can be as follows: The specific I have not tested, are derived from the network.

Jane, say it:

The file file name is a relative path that corresponds to the directory where the document using the #include directive resides. The included file can be in the same level of directory or its subdirectories, but not in the previous level directory. File= "nav_head.htm", such as the nav_head.htm document that represents the current directory. The virtual file name is the full path to the dummy directory on the Web site. For example, the Nav_head.htm file that represents the Hoyi directory under the root directory of the server document; virtual= "/hoyi/nav_head.htm"

The above is the global configuration, if it is not written


Can be set in a single directory:

The configuration virtual directory can be set as follows:


Namevirtualhost www.xxx.com
<virtualhost www.xxx.com:80>
DocumentRoot f:xing ServerName www.xxx.com
</VirtualHost>
<directory "F:xxx" >
Options Indexes FollowSymLinks
Includes AddType text/html. shtml
Addoutputfilter INCLUDES. shtml
allowoverride None order Allow,deny allow from all
</Directory>


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.