Forum Moderators: phranque

Message Too Old, No Replies

.htaccess vs .user.ini

         

smallcompany

6:52 pm on Jul 10, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



So I had a site where PHP was configured as Apache, and at some point I moved it where it runs php using FastCGI and suEXEC. I noticed compression was not working even though I had a directive in .htaccess which worked fine on another server. A support personnel advised me to enter a line into .user.ini instead, because of the server configuration.

Now I wonder... how do I know what works and what does not via .htaccess in such server environment?

Thanks

keyplyr

12:13 am on Jul 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Seems they are running PHP as CGI, which is sometimes done in shared hosting but also be done with managed private servers. So the htaccess isn't seeing the PHP.

Along with other file types, did you try this in htaccess?
AddOutputFilterByType DEFLATE application/x-httpd-fastcgi
or
AddOutputFilterByType DEFLATE application/x-httpd-fastphp

phranque

2:43 am on Jul 11, 2017 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I had a directive in .htaccess which worked fine on another server. A support personnel advised me to enter a line into .user.ini instead, because of the server configuration.

Now I wonder... how do I know what works and what does not via .htaccess in such server environment?


which directive did you try in .htaccess and what did you try in user.ini?

it's possible that the filter you were declaring wasn't configured in the output filter chain.

Apache Filters:
http://httpd.apache.org/docs/current/filter.html [httpd.apache.org]

smallcompany

8:47 am on Jul 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thank you.

What I did was to add his line into the .user.ini:

zlib.output_compression = On

I still have this in .htaccess:

<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</IfModule>

Now, the online tools are showing compression as enabled (69%), but PageSpeed Insights is persistent that all of the local CSS and JS files could still be compressed.

Edit: I just checked single CSS file, and no compression was shown. so Google is right, CSS and JS are not being compressed for some reason.

[edited by: smallcompany at 9:07 am (utc) on Jul 11, 2017]

keyplyr

9:01 am on Jul 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Are you sure PageSpeed isn't saying something else isn't compressed, like 3rd party apps or Adsense code? There's a down arrow that says exactly what files aren't compressed.

smallcompany

9:25 am on Jul 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Nope, it's just local JS and CSS. As I said, I tested specific files in online tools, and they said the same, no compression enabled. I'll check with support.

smallcompany

9:51 am on Jul 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Got it!

This Drupal related conversation helped:

[groups.drupal.org...]

I added this into .htaccess:

<FilesMatch ".(js|css|html)$">
SetOutputFilter DEFLATE
</FilesMatch>

All is compressed now.

Thank you

phranque

9:58 am on Jul 11, 2017 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



the .user.ini file is a php configuration file and any compression-related directives here would only affect php output, which in your case is only the text/html output.

perhaps the DEFLATE filter wasn't configured in the output filter chain or the mod_filter apache module isn't enabled in your apache configuration.

phranque

10:00 am on Jul 11, 2017 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



SetOutputFilter DEFLATE


yeah - that...

smallcompany

10:27 am on Jul 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I see both ways here:

[httpd.apache.org...]

Yet, I would have no clue what to implement without this real life situation.

Plus, thanks for clarifying the PHP side thing, now it sounds logical, but not until I was told by you. :)

keyplyr

10:34 am on Jul 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In htaccess remove the opening and closing tags...<IfModule mod_filter.c> and </IfModule> .

But leave the directive. Then test with PageSpeed (or another tool) again.

phranque

10:43 am on Jul 11, 2017 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I see both ways here:

what do you mean by "both ways"?

smallcompany

1:45 pm on Jul 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



1. AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript
2. SetOutputFilter DEFLATE

In my case, the 2. worked as I posted above, combined with the FilesMatch.

lucy24

6:58 pm on Jul 11, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



:: detour to check a hunch ::

Yup. It's one of those Apache things where almost-identical-sounding directives involve different mods. In 2.2:

SetOutputFilter is core
AddOutputFilter is mod.mime
AddOutputFilterByType is core

In 2.4:

SetOutputFilter is (still) core
AddOutputFilter is (still) mod.mime
AddOutputFilterByType is mod.filter

Note further that the docs for Apache 2.2 under “AddOutputFilterByType” say
Because of certain problems discussed below, this directive is deprecated.

In 2.4 weirdly it is no longer deprecated; instead they moved it to a whole new mod.

What Apache version are you using?

smallcompany

6:55 am on Jul 13, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It says:

Apache/2.2.32

phranque

11:02 am on Jul 13, 2017 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Apache/2.2.32

AddOutputFilterByType enables filtering based on the MIME-type of the response.
AddOutputFilter enables filtering based on the MIME-type associated with the file extension, which is why it's a mod_mime directive.
SetOutputFilter enables filtering for all documents within the container (context) in which the directive is defined.

https://httpd.apache.org/docs/2.2/mod/core.html#addoutputfilterbytype
Note

Enabling filters with AddOutputFilterByType may fail partially or completely in some cases.
...