Apache2.2 (httpd.conf文件)配置 html、shtml来include网页文件

配置SSI:
环境:Apache2.2 (httpd.conf文件)配置 html、shtml来include网页文件


1、 去掉AddType text/html .shtml ,AddOutputFilter INCLUDES .shtml前面注释

    # Filters allow you to process content before it is sent to the client.
    #
    # To parse .shtml files for server-side includes (SSI):
    # (You will also need to add "Includes" to the "Options" directive.)
    #
    AddType text/html .shtml .html
    AddOutputFilter INCLUDES .shtml .html


2、查找Options Indexes FollowSymLinks 在后面加上INCLUDES

注意,SSI确实可以利用shell来执行命令,这个功能是极度危险的,因为它会执行任何包含在exec标记中的命令。如果用户有可能修改你的网页内容,那么你一定要关闭这个功能。可以在Options指令中加上IncludesNOEXEC参数,以关闭exec功能,同时又保留SSI。


<Directory "E:/website">  #修改E:/website网站目录

#    Options FollowSymLinks
#    AllowOverride None
#    Order deny,allow
#    Deny from all
      Options FollowSymLinks INCLUDES IncludesNOEXEC
      AllowOverride None
</Directory>


3、重新启动apache ,ok你的html、shtml就可以加载页面了。


4、用include命令包含页面。


include元素能按file属性或virtual属性判断应该包含的文件。file属性是一个相对于当前目录的文件路径,即不能是一个绝对路径(以"/"开头)或包含"../"的路径。virtual属性可能更有用,它是一个相对于被提供的文档的URL ,可以以"/"开头,但必须与被提供的文档位于同一服务器上。

<!--#include virtual="/header.html" -->

--------------------------------------------------------------------------------------------------


示例  
<!--被包含文件与父文件存在于相同目录中。 -->  
<!-- #include file = "myfile.inc" -->  

<!--被包含文件位于脚本虚拟目录中。 -->  
<!-- #include virtual = "/scripts/tools/global.inc" -->  

include file 与include virtual的区别  

1。#include file 包含文件的相对路径,#include virtual包含文件的虚拟路径。  
2。在同一个虚拟目录内,<!--#include file="file.asp"-->和<!--#include virtual="file.asp"-->效果是相同的,但假设虚拟目录名为myweb,则<!--#include virtual="myweb/file.asp"-->也可以通过调试,但我们知道<!--#include file="myweb/file.asp"-->是绝对要报错的。  
3。如果一个站点下有2个虚拟目录myweb1和myweb2,myweb1下有文件file1.asp,myweb2下有文件file2.asp,如果file1.asp要调用file2.asp,那么在file1.asp中要这样写:<!--#include virtual="myweb2/file2.asp"-->,在这种情况下用#include file是无法实现的,用<!--#include file="myweb2/file2.asp"-->必然报错。相反,在myweb2的文件中包含myweb1中的文件也是一样。如果该被包含文件在某个文件夹下面,只要在虚拟路径中加上该文件夹即可。  
4。不论用#include file 还是 #include virtual,在路径中用“/”还是“/”或者二者交叉使用都不会影响编译效果,程序会顺利执行。  
5。以上情况不适用于2个站点文件的相互调用,而且在同一个站点内,<!--#include file="file.asp"-->和<!--#include virtual="file.asp"-->等效,但假设站点名为website,使用<!--#include virtual="website/file.asp"-->是错误的。

猜你喜欢

转载自blog.csdn.net/guangrong1/article/details/79898375