需求:

假设index.html包含了header.html和footer.html。代码如下:

<!--#include virtual="header.html" -->
<main>
    Hello World!
</main>
<!--#include virtual="footer.html" -->

header.html如下:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>include HTML</title>
</head>

<body>

footer.html如下:

 </body>

 </html>
想要得到客户端浏览器源码:
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>include HTML</title>
</head>

<body>
    <main>
        Hello World!
    </main>
</body>

</html>

方法:

步骤1:Apache httpd.conf配置文件中开启如下三个模块:

LoadModule include_module modules/mod_include.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule expires_module modules/mod_expires.so

步骤2:httpd.conf配置文件底部添加:

AddType text/html .html 
AddHandler server-parsed .html 
Options Indexes FollowSymLinks Includes

步骤3:如果有指定过站点目录,那么也需要添加Options

<Directory "D:/www" >
    Options Indexes FollowSymLinks Includes
    AllowOverride All
    Require all granted
</Directory>

步骤4:重启apache服务即可。

注意,可能会跟下列配置冲突,可适当注释掉下面的代码。
AddType application/x-httpd-php html htm