我如何禁用它与Apache中的.htaccess SetEnvIfNoCase? [英] How do I disable GZip with SetEnvIfNoCase in Apache .htaccess?

查看:599
本文介绍了我如何禁用它与Apache中的.htaccess SetEnvIfNoCase?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要禁用它的某些页面。我有这个在我的的.htaccess ,但它仍然打开的GZip上(内容编码:gzip )访问时仪表板/指数

I want to disable GZip for certain pages. I have this in my .htaccess, but it still turns GZip on (Content-Encoding: gzip) when visiting 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

我尝试添加标题设置MyHeader%{REQUEST_URI} 来看看有什么 REQUEST_URI 是的,但它给了内部服务器错误。

I tried to add Header set MyHeader %{REQUEST_URI} to see what the Request_URI was, but it gave an Internal Server Error.

我也试过正则表达式仪表板/指数仪表板/指标。* /仪表板/指标等,并试图 SetEnvIfNoCase REQUEST_URI ... ,但GZip压缩还开着。

I also tried the regex dashboard/index, dashboard/index.*, "/dashboard/index", etc., and tried SetEnvIfNoCase REQUEST_URI ..., but GZip was still on.

如果我评论 #AddOutputFilterByType ,然后Gzip已关闭。

If I comment #AddOutputFilterByType, then GZip is turned off.

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

I'm using Apache 2.4.16, Yii 2.0.7, PHP. I'm using FPM in production, so apache_setenv() is not available.

推荐答案

你可能使用重写摆脱的index.php文件在URL中。由于阶段,使得 SetEnvIf之后请求过程中运行,的index.php 将是<$ C $的一部分用c> REQUEST_URI VAR(这是不同于%{REQUEST_URI} )。

You're probably using rewrites to get rid of index.php in the URL. Due to the stage at which SetEnvIf runs during the request, index.php will be part of the Request_URI var used (which is distinct from %{REQUEST_URI}).

这是时下相当普遍,不使用 PATH_INFO 的重写,而只是说白了重写的index.php ,其中code只是读取原始 REQUEST_URI 信息。在 SetEnvIf之后这种情况下, REQUEST_URI 将只是的index.php,所以你需要设置一个标志的环境变量针对该URL的特殊虚拟重写,后来与一个重定向_ preFIX(因为是重写内部重定向阶段,mod_rewrite的$ p引用它$ pfixes所有现有的包膜与瓦尔REDIRECT _

It's nowadays quite common to not use PATH_INFO for rewrites, but just plainly rewrite to index.php, where code just reads the original REQUEST_URI info. In that case, Request_URI in SetEnvIf will be just "index.php", so you'd need to set a flag env var in a special dummy rewrite for that URL, and reference it later with a REDIRECT_ prefix (as there is an internal redirect stage on rewrites where mod_rewrite prefixes all existing env vars with 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/foobar 如用重写规则的index.php / $ 1 规则)(。*):

There is a slightly less verbose way if you rewrite to PATH_INFO (so "/foobar" turns to "/index.php/foobar" using e.g. a RewriteRule (.*) index.php/$1 rule):

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

但是,这似乎更脆弱,因为它如果你改变了重写规则力学会打破。

这篇关于我如何禁用它与Apache中的.htaccess SetEnvIfNoCase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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