apache配置-html碎片shtml格式

修改SSI 文件

conf–httpd.conf

<Directory "D:/Android/Apache2.2/htdocs">  //修改文件目录

    #

    # Possible values for the Options directive are "None", "All",

    # or any combination of:

    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

    #

    # Note that "MultiViews" must be named *explicitly* — "Options All"

    # doesn't give it to you.

    #

    # The Options directive is both complicated and important.  Please see

    # http://httpd.apache.org/docs/2.2/mod/core.html#options

    # for more information.

    #

    Options Indexes FollowSymLinks Includes //添加include

    #

    # AllowOverride controls what directives may be placed in .htaccess files.

    # It can be "All", "None", or any combination of the keywords:

    #   Options FileInfo AuthConfig Limit

    #

    AllowOverride None

    AddType text/html .shtml  

    AddOutputFilter INCLUDES .shtml //添加include

    #

    # Controls who can get stuff from this server.

    #

    Order allow,deny

    Allow from all

</Directory>

<IfModule dir_module>

   DirectoryIndex index.html index.shtml  //这个是添加默认的索引文件

</IfModule>

<Directory "D:/htdocs/test">  //修改文件目录

    AllowOverride None

    Options None

    Order allow,deny

    Allow from all

</Directory>

详解:

如何使你的Apache服务器支持SSI?

Apache(如何在windows以及linuc下安装apache请参见另两篇文章)默认是不支持SSI的,需要我们更改httpd.conf来进行配置。我这里以windows平台的Apache 2.0.x为例(在linux平台下与之相同),打开conf目录下的httpd.conf文件,搜索“AddType text/html .shtml”,找到:

以下是引用片段:
# AddType text/html .shtml 
# AddOutputFilter INCLUDES .shtml

把这两行前面的#去掉 。

然后搜索“Options Indexes FollowSymLinks”

在搜索到的那一行后面添加“ Includes”

即将该行改变为 Options Indexes FollowSymLinks Includes

熟悉apache manual的可能会觉得比较容易。

保存httpd.conf,重起apache即可

到此我们就完成了对Apache SSI的设置。

cmd命令检查配置文件:

httpd.exe -t

总结如下:

方法1–apache配置:


1. 确认加载include.so模块,将注释去掉: 
LoadModule include_module libexec/apache2/mod_include.so 


2. AddType部分去掉这两段注释: 
AddType text/html .shtml 
AddOutputFilter INCLUDES .shtml 


3. Directory目录权限里面找到 
Options Indexes FollowSymLinks 
增加Includes修改为: 
Options Indexes FollowSymLinks Includes 


4. 重新启动Apache,测试: 
<!–#include file=”head.html”–> 
Holle Word!,这是中间的内容 
<!–#include file=”foot.html”–>

方法2–.创建文件.htaccess

如果用户不能直接访问服务器配置文件,可以使用文件编辑器创建一个名为.htaccess的文件。注意,文件名前一定要有符号“.”,这样服务器才能知道该文件是隐藏文件,从而提高文件的安全性,避免错误操作。在.htaccess文件中需要加入以下三行文字:
Options Indexes FollowSymLinks Includes 
AddType application/x-httpd-CGI .CGI 
AddType text/x-server-parsed-html .shtml
完成之后可以把.htaccess文件上传到服务端的相应目录,该文件对所有子目录有效。如果用户希望在目录级上禁止CGI或shell命令,可以在.htaccess文件中的Options选项行加入关键字IncludesNOEXEC

在页面中引入shtml代码:

<!--#include virtual="inc/head.shtml"-->
<!--#include virtual="inc/footer.shtml"-->

如果需要使用html解析包含,  

AddType application/x-httpd-CGI .CGI 
AddType text/x-server-parsed-html .shtml在 它后面添加


添加 AddOutputFilter INCLUDES .html 到下面即可

原文地址:https://www.cnblogs.com/moqiutao/p/7119484.html