如何使用 htaccess 自动将 html 标题添加到文件夹的所有 html 页面? [英] How to add a html header to all html pages of a folder automatically with htaccess?

查看:21
本文介绍了如何使用 htaccess 自动将 html 标题添加到文件夹的所有 html 页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过了

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 问题都不是您想要的:

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:

这篇关于如何使用 htaccess 自动将 html 标题添加到文件夹的所有 html 页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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