如何使用 htaccess 自动将 html 标题添加到文件夹的所有 html 页面? [英] How to add a html header to all html pages of a folder automatically with htaccess?
问题描述
我试过了
Options +IndexesIndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8标题名称/header.html自述文件名/footer.htmlIndexIgnore header.html footer.html .htaccess
如何包含使用 .HTACCESS 或其他方法的 PHP 文件站点范围
将 .htaccess HeaderName 应用到所有较低级别?>
如何包含使用 .HTACCESS 或其他方法的 PHP 文件站点范围
它只是什么都不做.我还按照旧指南启用了布局标题(apache 中带有 mod_layout 的东西),但它似乎太旧了.
我设法做的最好的事情是将header.html"的内容显示到目录中(与 Option +Indexes 一起列出)
我在特定文件夹 .htaccess 中执行所有这些操作,而不是在根目录 .htaccess 中它看起来像这样:
Options +Indexes
IndexOptions IgnoreCase FancyIndexing FoldersFirst NameWidth=* DescriptionWidth=* SuppressHTMLPreambleHeaderName header.html
请帮忙
我认为您将 HTTP 标头与 HTML标头"(即页面顶部)混淆了
HTTP 标头用于定义编码、内容类型(例如 JSON/XML)等内容,而不是将 HTML 添加到另一个 HTML 页面的顶部.
如果您想将 HTML 添加到每个页面的顶部,.htaccess 不是执行此操作的地方 - 您需要使用某种脚本/编程语言(例如 ASP/PHP)来包含文件.
请注意,您链接的三个 SO 问题都不是您想要的:
- 如何包含使用 .HTACCESS 或其他方法的 PHP 文件站点范围 和 如何使用 .HTACCESS 或其他方法在站点范围内包含 PHP 文件 都使用 PHP 来包含文件(并且只需使用 htaccess 告诉 PHP 在哪里可以找到这些文件).
- 将 .htaccess HeaderName 应用于所有较低级别?发现后,仅将标题添加到 Apache 目录列表 页面,而不是添加到您网站上的每个页面.
I tried this
Options +Indexes
IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8
HeaderName /header.html
ReadmeName /footer.html
IndexIgnore header.html footer.html .htaccess
How To Include a PHP File Site-wide Using .HTACCESS or other methods
Apply .htaccess HeaderName to all lower levels?
How To Include a PHP File Site-wide Using .HTACCESS or other methods
It just simply does not do anything. I also followed an old guide to enable Layout Header (something with mod_layout in apache) but it seems it's too old.
The best i managed to do is to show the content of my "header.html" into the directory (which is listed with Option +Indexes)
I am doing all of this in a specific folder .htaccess, not in the root .htaccess It looks like this :
Options +Indexes
IndexOptions IgnoreCase FancyIndexing FoldersFirst NameWidth=* DescriptionWidth=* SuppressHTMLPreamble HeaderName header.html
Please, help
I think you're confusing HTTP Headers with a HTML "Header" (meaning the top of the page)
A HTTP header is used to define things like the encoding, content type (eg JSON/XML), not to add HTML to the top of another HTML page.
If you want to add HTML to the top of each page, .htaccess isn't the place to do this - you need to use some kind of scripting/programming language (eg ASP/PHP) to include the files.
Note that none of the three SO questions you link do what you want either:
- How To Include a PHP File Site-wide Using .HTACCESS or other methods and How To Include a PHP File Site-wide Using .HTACCESS or other methods both use PHP to include the files (and just use htaccess to tell PHP where to find the files).
- Apply .htaccess HeaderName to all lower levels? as you discovered, adds the header to the Apache directory listing page only, not to every page on your site.
这篇关于如何使用 htaccess 自动将 html 标题添加到文件夹的所有 html 页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!