Apache under Open SSI Configuration enables HTML to support include methods _linux

Source: Internet
Author: User
Tags html tags parent directory

Students who write the page often encounter such a problem, that is, more and more HTML tags on the page, it will be difficult to find the specified part, then can be written in different files like JavaScript to introduce it? The answer is yes, Apache can do it.

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 (#).

2016.01.11 MORE:

This step is not necessary for local testing, thanks to Whuper.

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 Options Indexes FollowSymLinks , add the INCLUDES at the back, and change to 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 file parameters:

<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.

Reference:

Let Apache support sHTML (SSI) configuration methods

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.