.htaccess Internal Server Error while enabling Gzip - php

I am trying to enable Gzip compression on my wordpress website. But when i try to add the compression code, i am getting the following error.
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at webmaster#coachhire4u.com to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
Apache/2.4.18 (Unix) OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 PHP/5.5.31 Server at www.coachhire4u.com Port 80
My .htaccess file,
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/customer/quote/payment/
RewriteRule (\d+)/(\d+) http://www.coachhire4u.com/?c4u_payment_id=$1
[L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Compression code
# Compress HTML File, CSS File, JavaScript File, Text File, XML File and Fonts
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
Please help me to resolve this issue. I know there are similar posts, but none of them seem to help
thanks

There are different approchaes of achieving compression. Which one to use depends on the capabilities/setup of your server. It's always a good idea to surround blocks with <ifModule></ifModule> where possible, in order to prevent 500 status errors.
There's a good chance that the following will work on your local machine as well as on your server. However, with the sparse informatione provided, it's not possible to give a definite answer. But I'll gladly update this answer if this does not work and you can provide further debugging information.
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|json|php|pl|svg)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^application/json.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
<ifModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/xml text/css text/plain
AddOutputFilterByType DEFLATE image/svg+xml application/xhtml+xml application/xml
AddOutputFilterByType DEFLATE application/rdf+xml application/rss+xml application/atom+xml
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript application/json
AddOutputFilterByType DEFLATE application/x-font-ttf application/x-font-otf
AddOutputFilterByType DEFLATE font/truetype font/opentype
</ifModule>
AddType image/svg+xml svg svgz
AddEncoding gzip svgz

It might be a bit late, but I hope this helps.
I fixed my error by going to httpd.conf for my Apache server configuration and uncommenting the lines containing mod_filter.so and mod_deflate.so.

Related

WordPress compression not working on localhost, XAMPP

I need some help with WordPress speed optimization via .htaccess.
For now, the website is still running on localhost, XAMPP, Apache v3.2.4.
What I did / tried:
turn on GZip in .htaccess
enable mod deflate in .htacess
place .htaccess in WordPress root directory
Google Lighthouse Speed Test via the Chrome dev tools does not detect:
Compression (message: Enable text compression)
When I examine the response header via dev tools, there's no cache-control: ... entry.
I would appreciate some help on how to fix these problems. I figure that I went wrong somewhere in my setup, but I'm not sure where.
So, here's what I did for COMPRESSION in .htacces:
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
# For Olders Browsers Which Can't Handle Compression
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<IfModule mod_headers.c>
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME}\.gz -f
RewriteRule \.(css|ics|js|json|html|svg)$ %{REQUEST_URI}.gz [L]
# Prevent mod_deflate double gzip
RewriteRule \.gz$ - [E=no-gzip:1]
<FilesMatch "\.gz$">
# Serve correct content types
<IfModule mod_mime.c>
# (1)
RemoveType gz
# Serve correct content types
AddType text/css css.gz
AddType text/calendar ics.gz
AddType text/javascript js.gz
AddType application/json json.gz
AddType text/html html.gz
AddType image/svg+xml svg.gz
# Serve correct content charset
AddCharset utf-8 .css.gz \
.ics.gz \
.js.gz \
.json.gz
</IfModule>
# Force proxies to cache gzipped and non-gzipped files separately
Header append Vary Accept-Encoding
</FilesMatch>
# Serve correct encoding type
AddEncoding gzip .gz
</IfModule>

Apache GZip not working text files and js files?

I am trying to add GZip compression using Apache mod_deflate module. All contents get compressed except text files(".txt"). Also facing issues when compressing HTML files and JS files.
For Example: Let's say a script file ("main.js") hosted on http://example.com
The contents of file:
In case 1:
// Contents of main.js
console.log("Hello World");
console.log("Hello World");
console.log("Hello World");
console.log("Hello World"); console.log("Hello World");
In case 2:
// Contents of main.js
Hello World! Hello World!
Hello World! Hello World! Hello World!
Hello World! Hello World! Hello World! Hello World!
Random Contents
In case 1, When I visit http://example.com/main.js, it shows content-encoding: gzip.
In case 2, When I visit http://example.com/main.js, it doesn't show any content-encoding: gzip header.
So the GZip only works in Case 1 for .js files.
GZip not working on text files(.txt extension) and not showing any content-encoding: gzip header.
// .htaccess code
<IfModule mod_deflate.c>
<IfModule mod_mime.c>
AddType text/plain .txt
</IfModule>
SetOutputFilter DEFLATE
</IfModule>
My software list
Apache Version - 2.4.39
PHP Version - 7.3
OS - Windows 10
Software - Wamp 64Bit
If you add default mod_deflate and mod_gzip conf in .htaccess file some changes?
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_include handler ^cgi-script$
</IfModule>

Site doesn't work on localhost with the ".htaccess"

I neet to put a CMS that i got, to work on localhost, the problem is that it is working only if i delete the .htaccess file. If the .htaccess is in the root folder the site doesn't work and when i delete the .htaccess file and the site is working i can't access the admin pannel using "http://localhost/putina/admin", I receive the error "The requested URL /putina/admin was not found on this server.". Here is my .htaccess:
Options -Indexes
RewriteEngine On
#RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [L]
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
<filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=2592000, public"
</filesMatch>

gzip compression not working on xampp

for some reason the gzip is not working
my gzip compression script
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
i am using:----
XAMPP server.last time updated:2 min before the time of this question
NOTE:ALL FILES ARE A .PHP FILE,AND .HTACCESS FILES ARE IN ROOT FOLDER
HOW I FOUND OUT THAT IT IS NOT BEING GZIPPED:BY RUNNING AUDIT IN GOOGLE CHROME (DEVELOPER TOOLS)
Uncomment this line on httpd.conf
LoadModule deflate_module modules/mod_deflate.so
LoadModule filter_module modules/mod_filter.so
I'm betting your xampp install is not very old and you're probably using a recent version of Apache. So you should use mod_deflate.
mod_gzip is for Apache 1.x and mod_deflate is Apache 2.x
You can try this and customize as needed.
<IfModule mod_deflate.c>
<FilesMatch "\.(html|txt|css|js|php|pl)$">
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
Or you can try it this way as well.
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE image/jpeg
AddOutputFilterByType DEFLATE image/png
AddOutputFilterByType DEFLATE image/gif
#Custom Setting End.
You may also have to enable it in the Apache config. So you would uncomment this line and restart Apache.
LoadModule deflate_module modules/mod_deflate.so
You can also see gzip info here.
http://developer.yahoo.com/performance/rules.html#gzip

500 error when compressing files with .htaccess

I'm trying to compress files with .htaccess but I'm getting a 500 internal error,
This is the code I'm trying to use.
# JavaScript compression htaccess ruleset
AddHandler application/x-httpd-php .js
php_value auto_prepend_file gzip-js.php
php_flag zlib.output_compression On
I've also tried this but getting the same error,
<files *.html>
SetOutputFilter DEFLATE
</files>
Any suggestions why?
Do you have mod_deflate installed? Try this instead and see if your error goes away.
<ifModule mod_deflate.c>
<Files *.html>
SetOutputFilter DEFLATE
</Files>
</ifModule>
If this resolves the 500 error, then you probably don't have mod_deflate installed. You can test it by visiting HTTP Compression Test.
If you have access, you may be able to enable it by uncommenting the following lines in your httpd.conf file.
LoadModule filter_module modules/mod_filter.so
LoadModule deflate_module modules/mod_deflate.so
Then you will need to add an output type for each file type you wish to compress.
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
As mentioned in the comments, AddOutputFilterByType depends on mod_filter. If you still get a 500 error you should check that this module is loaded too.
You can read more here: Use mod_deflate to Compress Web Content delivered by Apache
I can't find any documentation that suggests whether Siteground supports mod_deflate or not. Their KB suggests using gZip from PHP.
How to enable gZIP compression for your pages?
How to compress my CSS with gZIP?
After spending hours of search I found this article, thought someone else might find it helpful,
Enjoy.
## DEFLATE ##
#mod_filter.so and mod_deflate.so
should be ON !!!!
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
This worked fine for me (paste in .htaccess):
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

Categories