简体   繁体   English

AddHandler无法用于.php文件-Apache 2.4

[英]AddHandler not working for .php files - Apache 2.4

I am creating a dummy handler for .php and .html files called helloworld . 我正在为名为helloworld .php和.html文件创建虚拟处理程序。 The handler contains this: 处理程序包含以下内容:

static int helloworld_handler(request_rec *r){
    ap_rprintf(r, "hello world!");
    return OK;
}

I have got this in apache2.conf: 我在apache2.conf中得到了这个:

<Directory /var/www/html>
AddHandler helloworld .php .html
</Directory>

The handler "helloworld" is working for .html files, but it is not working for .php files. 处理程序“ helloworld”适用于.html文件,但不适用于.php文件。 I think it is mostly because the default php handler overrides the helloworld handler for .php files. 我认为主要是因为默认的php处理程序会覆盖.php文件的helloworld处理程序。 How do I make "helloworld" handler work for .php files? 如何使“ helloworld”处理程序可用于.php文件?

If there is any extra information required please ask. 如果需要任何其他信息,请询问。

You might want to try SetHandler instead 您可能想尝试SetHandler

<FilesMatch \.php$>
    SetHandler helloworld
</FilesMatch>

SetHandler will remove any previously set handler. SetHandler将删除任何以前设置的处理程序。 To get the option for your handler to run first then run the default PHP handler when your handler returns DECLINE you need to set yours first, then add PHP 要获得处理程序先运行的选项,然后在处理程序返回DECLINE时运行默认的PHP处理程序,您需要先进行设置,然后添加PHP

<FilesMatch \.html$>
    SetHandler helloworld .html
</FilesMatch>
<FilesMatch \.php$>
    SetHandler helloworld .php
    AddHandler php5-script .php
</FilesMatch>

Note that this has the effect of clearing any handlers previously setup for .html files 请注意,这具有清除以前为.html文件设置的所有处理程序的作用。

You can only have one handler handle any file type per request. 每个请求只能有一个处理程序处理任何文件类型。 If you always want the PHP interpreter to run first and then your handler to run second you could consider AddOutputFilter directive. 如果您始终希望先运行PHP解释器,然后再运行处理程序,则可以考虑使用AddOutputFilter指令。

Most phases are terminated by the first module that handles them; 大多数阶段都由处理它们的第一个模块终止。 however, for logging, `fixups', and non-access authentication checking, all handlers always run (barring an error). 但是,对于日志记录,“修复程序”和非访问身份验证检查,所有处理程序始终运行(除非出现错误)。

Apache API reference Apache API参考

AddOutputFilter docs AddOutputFilter文档

You need to restart your Apache server after adding handler. 添加处理程序后,您需要重新启动Apache服务器。

Check also if extension will actually be interpreted by the server the way you want it to work. 还检查扩展名是否实际上将由服务器按照您希望其工作的方式进行解释。 You can check that sort of info from system admin of your hosting provider. 您可以从托管服务提供商的系统管理员中查看此类信息。 Many sysadmins disable some features to improve security. 许多系统管理员禁用某些功能以提高安全性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM