到目前为止我遇到的简单问题总是通过PHP解决:
您有一个包含标题,菜单,页脚和内容字段的网站.
每页的页眉,菜单和页脚通常都是相同的.
因此,例如,您没有十个页面(如home.html,products.html,about.html,..)都在其html文件中拥有静态标题和菜单的副本.现在,如果要更改标题,则必须更改十个文件.
我希望我的问题足够清楚,如果不是,请发表评论:)
如果您使用的是Apache,则可以使用服务器端包含.这些基本上提供HTML文档中的include语句.
安装并启用mod_include.配置
Options +Includes
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
Run Code Online (Sandbox Code Playgroud)
使用.shtml为您的主页文件扩展名.然后在你的页面中,你可以做类似的事情
<!--#include virtual="/header.html" -->
Run Code Online (Sandbox Code Playgroud)
Nginx还支持服务器端包含它的SSI模块:
location / {
ssi on;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<!--# include file="header.html" -->
Run Code Online (Sandbox Code Playgroud)