简体   繁体   English

在.htaccess中检测对php_value / php_flag的支持以抑制错误 - PHP CGI模式 - mod_php

[英]Detect support for php_value / php_flag in .htaccess to suppress errors - PHP CGI mode - mod_php

I use php_value and php_flag rules in .htaccess such as: 我在.htaccess使用php_valuephp_flag规则,例如:

php_value upload_max_filesize 100M

But this causes an error when the server is running in CGI mode instead of Apache mode, and instead I have to use php.ini rules such as: 但是当服务器以CGI模式而不是Apache模式运行时,这会导致错误,而我必须使用php.ini规则,例如:

upload_max_filesize = 100M

My code libraries needs to work for either mode, without manual changes for each server. 我的代码库需要适用于任一模式,无需为每个服务器进行手动更改。

It took me a while to find a solution to allow both methods to be in place, and as it was hard to find I thought I'd post my solution here. 我花了一段时间才找到允许两种方法到位的解决方案,因为很难找到我认为我会在这里发布我的解决方案。

You can detect mod_php in .htaccess and ensure that these directives are only attempted when supported. 您可以在.htaccess中检测mod_php ,并确保仅在支持时尝试使用这些指令。 In .htaccess: 在.htaccess中:

<IfModule mod_php5.c>
   php_value upload_max_filesize 100M
   php_flag ...
</IfModule>

Note: Depending on your setup you might need to change mod_php5.c to mod_php4.c or mod_php.c . 注意:根据您的设置,您可能需要将mod_php5.c更改为mod_php4.cmod_php.c

In addition, you can manually stop the redundant php.ini file from being publicly accessible when in php mode using the following in .htaccess: 此外,您可以手动停止冗余的php.ini文件,以便在php模式下使用.htaccess中的以下内容进行公开访问:

<Files ~ "\.ini">
   Order allow,deny
   Deny from all
</Files>

Hope this saves you some time! 希望这能节省你一些时间!

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

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