在.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

查看:130
本文介绍了在.htaccess中检测对php_value / php_flag的支持以抑制错误-PHP CGI模式-mod_php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 .htaccess php_value php_flag 规则>例如:

I use php_value and php_flag rules in .htaccess such as:

php_value upload_max_filesize 100M

但是当服务器以CGI模式而不是Apache模式运行时,这会导致错误,而我必须使用php.ini规则,例如:

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:

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.

推荐答案

您可以检测到 mod_php 并确保仅在受支持时才尝试使用这些指令。在.htaccess中:

You can detect mod_php in .htaccess and ensure that these directives are only attempted when supported. In .htaccess:

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

注意:根据您的设置,您可能需要更改 mod_php5.c mod_php4.c mod_php.c

Note: Depending on your setup you might need to change mod_php5.c to mod_php4.c or mod_php.c.

此外,您可以使用.htaccess中的以下命令手动停止冗余php.ini文件在php模式下公开访问:

In addition, you can manually stop the redundant php.ini file from being publicly accessible when in php mode using the following in .htaccess:

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

希望可以为您节省一些时间!

Hope this saves you some time!

这篇关于在.htaccess中检测对php_value / php_flag的支持以抑制错误-PHP CGI模式-mod_php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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