The SSI configuration is enabled under Apache to enable html to support the methods included in include

  • 2020-05-12 06:37:41
  • OfStack

Students who write pages often have trouble finding specific parts of the page when there are more and more html tags on the page, so can they be written in different files like javascript 1? The answer is yes, apache can.

A simple example would be having the following html file (named index.html) :


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

1 simple text box and button, I now want to write the html of the button part in another.html file (say, btn.html) and then import it into index.html, how do I do that?

1. Load the ssi module

First you load the ssi module. Open the apache configuration file httpd.conf, which should be familiar, as mentioned several times in the previous article. Find the line LoadModule ssl_module modules/ mod_ssl.so and remove the preceding comment (#).

2016.01.11 more:

After local testing, this step is not required, thanks whuper for pointing it out.

2. Add the required file type

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


AddType text/html .shtml 
AddOutputFilter INCLUDES .shtml

If you have comments, remove them. Because the default file using ssi technology is called.shtml, we need to set the suffix.shtml in the configuration file and set the file type that needs to be parsed by ssi technology according to our own requirements.

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


AddType text/html .shtml .html
AddOutputFilter INCLUDES .shtml .html

3. Add INCLUDES
Again, in the httpd.conf file, find this 1 line Options Indexes FollowSymLinks , and then add INCLUDES, which looks like this:

Options Indexes FollowSymLinks INCLUDES

It is important to note that ssi can use shell to execute commands, so this feature is dangerous. It will execute any commands contained in the exec tag. If your user has permission to modify your web content, it is recommended to turn this feature off. Of course, you can also turn off exec by adding the IncludesNOEXEC parameter, while keeping SSI. This is changed to: Options Indexes FollowSymLinks INCLUDES IncludesNOEXEC

4. Restart apache

Last but not least, when you restart apache, you should never forget that when some children start to configure apache, they often say that it doesn't work, and most of the time they just forget to restart apache.

5, practice
With this configuration, we can introduce the html file into the html page, such as:


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

You can also use file Parameters:


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

What difference does it make...

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

In layman's terms, virtual is equivalent to an absolute path (from the server root), while file is equivalent to a relative path (and not yet in a parent directory). So virtual for 1 is ok.

Reference:

Have Apache support the configuration method of SHTML(SSI)


Related articles: