0

我想为某些页面禁用 GZip。我有这个.htaccess,但在访问时它仍然打开 GZip ( Content-Encoding: gzip) dashboard/index

<ifmodule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
  SetEnvIfNoCase Request_URI /dashboard/index no-gzip dont-vary

我试图添加Header set MyHeader %{REQUEST_URI}以查看是什么Request_URI,但它给出了内部服务器错误。

我还尝试了正则表达式dashboard/index, dashboard/index.*,"/dashboard/index"等,并尝试了SetEnvIfNoCase REQUEST_URI ...,但 GZip 仍在运行。

如果我发表评论#AddOutputFilterByType,则 GZip 将被关闭。

我正在使用 Apache 2.4.16、Yii 2.0.7、PHP。我在生产中使用 FPM,所以apache_setenv()不可用。

4

1 回答 1

3

您可能正在使用重写来摆脱index.phpURL。由于SetEnvIf在请求期间运行的阶段,index.php将成为Request_URI使用的 var 的一部分(与 不同%{REQUEST_URI})。

现在很常见的是不PATH_INFO用于重写,而只是简单地重写为index.php,代码只是读取原始REQUEST_URI信息。在这种情况下,Request_URIinSetEnvIf将只是“index.php”,因此您需要在该 URL 的特殊虚拟重写中设置一个标志 env var,并稍后使用REDIRECT_前缀引用它(因为有一个内部重定向阶段重写 mod_rewrite 为所有现有环境变量添加前缀的位置REDIRECT_

RewriteRule ^dashboard/index - [E=no-gzip:1]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
SetEnvIf REDIRECT_no-gzip 1 no-gzip

如果您重写为PATH_INFO(因此“ ”使用例如规则/foobar变为“ ”),则有一种稍微不那么冗长的方式:/index.php/foobarRewriteRule (.*) index.php/$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php/$1 [L]
SetEnvIfNoCase REQUEST_URI ^/index.php/dashboard/index.*$ no-gzip dont-vary

但这似乎更脆弱,因为如果您更改RewriteRule机制,它会破裂。

于 2016-03-25T00:25:32.380 回答