PHP共享标题,而不使用服务器端脚本? [英] PHP shared header without using sever-side scripting?

查看:74
本文介绍了PHP共享标题,而不使用服务器端脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



你有一个带有标题,菜单,页脚和内容字段的网站。



每个页面的标题,菜单和页脚通常都是相同的。


  • 没有PHP或任何其他服务器端语言,只有一个文件中存在标题,菜单和页脚数据?



例如,没有10个页面(如home.html,products.html,about.html,..),它们的html文件中都有一个静态页眉和菜单的副本。现在,如果您想更改标题,您必须更改十个文件。



我希望我的问题足够清晰,如果不是请留下评论:)

解决方案

如果您使用的是Apache,您可以使用服务器端包含。这些基本上提供了HTML文档中的include语句。



安装并启用 mod_include 。配置

 选项+包含
AddType文本/ html .shtml
AddOutputFilter INCLUDES .shtml

使用 .shtml 作为您的主页文件扩展名。然后在你的页面中,你可以做一些事情,比如:

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






Nginx也支持服务器端包含与它的SSI模块:

  location / {
ssi on;
}

HTML:

 <! - #include file =header.html - > 


Simple problem I have so far always solved via PHP:

You have a site with header, menu, footer and content field.

Header, menu and footer are usually the same for each page.

  • How do you, without PHP or any other server-side language, have the header, menu and footer data exist only in one file?

So that for example you don't have ten pages (like home.html, products.html, about.html, ..) all having a copy of the static header and menu in their html files. Now if you want to change the header you have to change ten files.

I hope I made my question clear enough, if not please leave a comment :)

解决方案

If you're using Apache, you can use server-side includes. These basically provide include statements within HTML documents.

Install and enable mod_include. Configure

Options +Includes
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

Use .shtml as your main page file extension. Then in your pages, you can do things like

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


Nginx also supports server-side includes with it's SSI module:

location / {
    ssi on;
}

HTML:

<!--# include file="header.html" -->

这篇关于PHP共享标题,而不使用服务器端脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆