我正在尝试在每个文件的开头添加一个 gzip 脚本
php_value auto_prepend_file gzip_start.php
在我的 .htaccess 中。问题是我已经有了一个名为 combine.php 的文档,它可以压缩它的内容。我需要知道的是,如何将 combine.php 从附加 gzip 的文件中排除。我考虑过使用文件匹配,但只能弄清楚如何在那个文件上执行它,而不是完全相反。
有任何想法吗?
将此代码放在 gzip_start.php 的开头:
if( preg_match("/.*combine\.php.*/i", $_SERVER['PHP_SELF']) ) {
// just output its content
}
else{
// output gzipped content
}
阅读 PHP 文档:
Specifies the name of a file that is automatically parsed before the main file.
The file is included as if it was called with the require() function, so
include_path is used.
在这种情况下,gzip_start.php 包含在您拥有的每个脚本中,combine.php 也包含在内,因此您可以检查哪个脚本包含该文件,然后进行压缩或如果必须忽略该文件则跳过它。