将大型html文件分成三个较小的html文件的最佳方法是什么? [英] What is the best way to separate a large html file into three smaller html files?
问题描述
我有一个非常大的网站,我想知道如何将一个HTML文件分成3个独立的HTML文件。为了将代码组织为一个整体的单个组件:
Header.html
body.html
Footer.html
如何破解html代码分成三个单独的html文件,但仍然使它们作为一个整体一起工作?
一个简单的方法是使用PHP连接3包括:
第1步)在您的.htaccess文件中,使您的服务器能够解析 .html
& .htm
档案为 .php
档案:
AddType应用程序/ x-httpd-php .html .htm
$步骤2)在
AddHandler应用程序/ x-httpd-php .html .htm
page.html
中,写入(仅)以下内容:p $ p>
<?php
include'/home/example/public_html/header.html';
包含'/home/example/public_html/body.html';
包含'/home/example/public_html/footer.html';
?>
注意
/ home / example / public_html /
是一个相对于根的服务器路径的例子。您需要将其更改为您自己的相对根服务器路径。
现在,当您将浏览器指向
页面.html
,你的服务器将把.html
文件解析为.php
文件,连接并将三个独立的PHP服务器端包含文件作为一个.html
文件提供。I have a very large website, and I was wondering how to separate a single HTML file into 3 separate HTML files. In order, to organize the code as individual components of a whole like this:
Header.html Body.html Footer.html
How can I break the html code into three separate html files but still make them work together as a whole?
解决方案A straightforward method would be to use PHP to concatenate 3 includes:
Step 1) In your .htaccess file, enable your server to parse
.html
&.htm
files as.php
files:AddType application/x-httpd-php .html .htm AddHandler application/x-httpd-php .html .htm
Step 2) In
page.html
, write (only) the following:<?php include '/home/example/public_html/header.html'; include '/home/example/public_html/body.html'; include '/home/example/public_html/footer.html'; ?>
N.B.
/home/example/public_html/
is an example relative-to-root server path. You'll need to change this to whatever your own relative-to-root server path is.Now, when you point your browser at
page.html
, your server will parse that.html
file as a.php
file and concatenate and deliver three separate PHP server-side include files as a single.html
file.这篇关于将大型html文件分成三个较小的html文件的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!