Welcome to WebmasterWorld Guest from 54.198.106.21

Forum Moderators: Ocean10000 & incrediBILL & phranque

.htaccess vs .user.ini

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 2, 2006
posts:2195
votes: 5


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
12:13 am on July 11, 2017 (gmt 0)

Moderator from US 

WebmasterWorld Administrator keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:8995
votes: 409


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
2:43 am on July 11, 2017 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10888
votes: 72


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]
8:47 am on July 11, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 2, 2006
posts:2195
votes: 5


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]

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

Moderator from US 

WebmasterWorld Administrator keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:8995
votes: 409


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.
9:25 am on July 11, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 2, 2006
posts:2195
votes: 5


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.
9:51 am on July 11, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 2, 2006
posts:2195
votes: 5


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
9:58 am on July 11, 2017 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10888
votes: 72


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.
10:00 am on July 11, 2017 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10888
votes: 72


SetOutputFilter DEFLATE


yeah - that...
10:27 am on July 11, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 2, 2006
posts:2195
votes: 5


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. :)
10:34 am on July 11, 2017 (gmt 0)

Moderator from US 

WebmasterWorld Administrator keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:8995
votes: 409


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.
10:43 am on July 11, 2017 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10888
votes: 72


I see both ways here:

what do you mean by "both ways"?
1:45 pm on July 11, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 2, 2006
posts:2195
votes: 5


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.
6:58 pm on July 11, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13841
votes: 485


:: 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?
6:55 am on July 13, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 2, 2006
posts:2195
votes: 5


It says:

Apache/2.2.32
11:02 am on July 13, 2017 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10888
votes: 72


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.
...
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members