在httpd.conf中设置标题不会在.htaccess中设置标题

编程入门 行业动态 更新时间:2024-10-20 09:20:54
本文介绍了在httpd.conf中设置标题不会在.htaccess中设置标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个奇怪的问题:

我有一堆标题,对于服务器上的每个网站都是相同的。我认为 只能在 httpd.conf 中设置一次,这样可以避免每次有新的添加时将写入.htaccess的内容写成一堆。

I have a bunch of headers that are the same for every website on a server. I think " this can be set just once in httpd.conf so as to save writing out into a pile of .htaccess every time there's a new one to add / change. "

这就是我要做的;

在 httpd.conf 文件中虚拟主机之前,我设置了:

<IfModule mod_headers.c> <Directory '/'> Header always set Feature-Policy "accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'" Header always set Cache-Control no-cache,must-revalidate Header always set X-Clacks-Overhead "GNU Terry Pratchett" Header always set X-XSS-Protection 1;mode=block Header always set X-Content-Type-Options nosniff Header always set X-Frame-Options SAMEORIGIN Header always set Content-Language en Header always set Referrer-Policy origin-when-cross-origin Header unset Last-Modified Header unset X-Powered-By Header always set Strict-Transport-Security "max-age=31536000;" "expr=%{HTTPS} == 'on'" Header always set Expect-CT enforce,max-age=2592000 </Directory> </IfModule>

但是,这样做并重新启动Apache(版本2.4.37)后,我发现或 .htaccess 中编辑的 Header 指令未发送。

However, after doing this and hard restarting the Apache (version 2.4.37), I find that additional or edited Header instructions in the .htaccess are not being sent.

例如;每个帐户都有自己的CSP策略,这反映在帐户 public_html / .htaccess 文件中:

For example; each account has its own CSP policy and this is reflected in the account public_html/.htaccess file:

示例:

Header set Content-Security-Policy "upgrade-insecure-requests; default-src 'self' https:;"

但是任何浏览器读取标头时,接收到的标头只是来自httpd.conf的标头并且 .htaccess 中没有显示其他标题或更改过的标题。

But when the headers are read by any browser the headers recieved are only the ones from the httpd.conf and no addditional or changed headers are showing from the .htaccess.

我不知道为什么?

  • 我将标头包裹在<$限定符< IfModule ...> 语句中的c $ c> .htaccess 。
  • I已经使用了不同的浏览器来迫使apache重新读取 .htaccess文件。
  • 我已经阅读过google,找不到与htaccess读取标题混淆的httpd.conf引用。
  • .htaccess 文件的其他部分都可以正常读取。
  • I have wrapped the headers in the .htaccess in qualifier <IfModule ...> statements.
  • I have used different browsers to force apache to reread the .htaccess files.
  • I have read google and can find no reference of httpd.conf messing with htaccess reading of headers.
  • Other parts to the .Htaccess files are being read ok.
  • Apache 2.4版。 37
  • 在上述更改之前,所有这些标头都在 .htaccess 中起作用。据我所知,这不是 标头语法。
  • Apache version 2.4.37
  • All of these headers work in the .htaccess prior to the above changes. It's not Header syntax as far as I can tell.

任何帮助我们都会感激不尽。

Any help gratefully received.

推荐答案

经过大量探索,我发现发生这种情况的原因是由于PHP是通过CGI处理程序运行的。更改为 suphp 处理程序可立即解决此问题。

I found after much exploring that the reason this occurred was due to PHP being run via a CGI handler. Changing to suphp handler immediately resolved this issue.

请参见此问题/ answer 和此答案。

更多推荐

在httpd.conf中设置标题不会在.htaccess中设置标题

本文发布于:2023-11-01 02:12:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547949.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标题   会在   httpd   conf   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!