【问题标题】:Exclude a file in a filematch在文件匹配中排除文件
【发布时间】:2010-05-02 21:42:58
【问题描述】:

我正在尝试在每个文件的开头添加一个 gzip 脚本

php_value  auto_prepend_file  gzip_start.php

在我的 .htaccess 中。问题是我已经有了一个名为 combine.php 的文档,它可以压缩它的内容。我需要知道的是,如何将 combine.php 从附加 gzip 的文件中排除。我考虑过使用 filesmatch,但只能弄清楚如何仅在一个文件上执行此操作,而不是完全相反。

有什么想法吗?

【问题讨论】:

    标签: php gzip prepend


    【解决方案1】:

    把这段代码放在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 也包含在内,因此您可以检查哪个脚本包含该文件,然后进行压缩,如果必须忽略该文件,则跳过它。

    【讨论】:

    • 我已经尝试过这个解决方案,但觉得它不够令人满意。问题是不需要 cookie 的文件(图像等)现在请求 cookie。不必要的活动......如果服务器检测到文件,我不必像那样请求文件。
    猜你喜欢
    • 1970-01-01
    • 2014-06-26
    • 1970-01-01
    • 2017-12-09
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多