WordPress compression not working on localhost, XAMPP - php

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>

Related

i m customize my site in local xampp but site folder didn't display due to htaccess

i m put my site data folder in local xampp but folder didn't display to my local xampp folder due to htaccess ..... i try but i cann't display folder and also didn't open my site in local........what can i do .this is my htaccess file what changes is due
Options All -Indexes
AddDefaultCharset utf-8
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^robots\.txt$ robots.%{HTTP_HOST}.txt [NC,QSA,L]
RewriteRule ^(Admin) - [NC,QSA,L]
RewriteRule ^([^/\.]+)/?$ index.php?lang=$1 [NC,QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?lang=$1&page=$2 [NC,QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?lang=$1&page=$2&one=$3 [NC,QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?lang=$1&page=$2&one=$3&two=$4 [NC,QSA,L]
<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
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>
<files *.html>
SetOutputFilter DEFLATE
</files>
<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 30 days"
</IfModule>
Header unset ETag
FileETag None
</FilesMatch>
ExpiresActive On
ExpiresByType image/jpeg "modification plus 1 minutes"
ExpiresByType image/png "modification plus 1 minutes"
ExpiresByType application/x-font-woff "access plus 1 years"
ExpiresByType text/css "modification plus 1 seconds"
ExpiresByType application/javascript "modification plus 1 seconds"
ExpiresDefault "access plus 1 minutes"
Displaying folder need option +Indexes
Remove -Indexes and add :
Options +Indexes

Mamp - Getting Gzip to work

How do you get gzip to work on a Wordpress site setup in MAMP?
I've got gulp creating the file /dist/css/main.css.gz and have added it to the header PHP file of my wordpress site.
I then lose all of my styling. I'm assuming this is because I haven't enabled it in my .htaccess? So I found the following code to add to my .htaccess:
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
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>
And it still does not work.
I'm not sure why you'd want to store your files as gzip archives, but this is not the way to do it. AddOutputFilterByType DEFLATE text/css will compress the file before sending it. To decompress an existing file, something like this will work (tested with 2.2):
<Directory />
AddOutputFilter INFLATE gz
RemoveType .gz
AddType text/css .css.gz
</Directory>
Test output:
$ echo "body {color:black; background:white;}" > foo.css
$ gzip foo.css
$ curl http://localhost/foo.css.gz
body {color:black; background:white;}
$ curl -I http://localhost/foo.css.gz
HTTP/1.1 200 OK
Date: Fri, 07 Jul 2017 23:01:22 GMT
Server: Apache/2.2.15 (Scientific Linux)
Last-Modified: Fri, 07 Jul 2017 22:59:22 GMT
Content-Length: 38
Content-Type: text/css
$
Of course, this interferes with your ability to serve actual gzip files, and you'll need to manually specify MIME types for each compressed file.
Also, if you're controlling the server you should not be using .htaccess files. They're slow and present a security risk. Put this in the server configuration!

PHP disable zlib.output_compression

My site has zlib.output_compression set to On in the ini file, it will compress all response when sending to the browser.
How to disable the compression only for binary file, PDF file and excel file so it will output to the browser correctly when download a file ?
Use a .conf file in your server, restricting compression to the right MIME types
for example in /etc/httpd/conf.d/enable_mod_deflate.conf:
# mod_deflate configuration
<IfModule mod_deflate.c>
# Restrict compression to these MIME types
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xml+rss
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE image/png
AddOutputFilterByType DEFLATE image/gif
AddOutputFilterByType DEFLATE image/jpeg
# Level of compression (Highest 9 - Lowest 1)
DeflateCompressionLevel 9
# Netscape 4.x has some problems.
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
<IfModule mod_headers.c>
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>
don't forget to restart your servers
sudo service httpd restart
zlib.output_compression = on/off
and in PHP
ini_set("zlib.output_compression", "On");
ini_set("zlib.output_compression", "Off");
Check this one for more details - http://php.net/manual/en/zlib.configuration.php#ini.zlib.output-compression

.htaccess doesn't work on custom folders in codeigniter

I have my site running in Codeigniter. I have my own folder names custom where I have placed a simple .htaccess which has
Deny from all
But when i hit www.example.com/custom, it shows all files in browser. However, If I hit www.example.com/system, it says "Directory access is forbidden."
My folder structure is as follows.
mysite
mysite/system
mysite/custom
mysite/application
....
I have different .htaccess in root file and the redirection works fine.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
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 font/woff
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
ExpiresActive On
ExpiresDefault A0
<FilesMatch "\.(ico|ICO|pdf|PDF|flv|FLV|jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF|js|JS|css|CSS|swf|SWF)(\.gz)?$">
ExpiresDefault "access plus 10 years"
Header append Cache-Control “publicâ€
Header unset ETag
FileETag None
Header set Expires "Thu, 15 Apr 2025 20:00:00 GMT"
</FilesMatch>
<FilesMatch “\.(xml|txt|html)$â€>
ExpiresDefault A7200
Header append Cache-Control “proxy-revalidateâ€
</FilesMatch>
<FilesMatch “\.(js|css)$â€>
ExpiresDefault A259200
Header append Cache-Control “proxy-revalidateâ€
</FilesMatch>
</IfModule>
I have the
Deny from all
in rest of the sub folders. System and application folders comes with CI. htaccess works fine in this folder. But in my own created folder "custom", htaccess file is not working.
What might be the problem? Why it allows htaccess work in the default folders and why it is not working in the user created folders
Note: I have same setting working in my nginx server. I have a different site Im uploading now. It is not working on the apache folder.
Try this code in your /custom/.htaccess:
RewriteEngine On
Deny from all
Delete your browser cache with (CTRL + F5) for WINDOWS or (Command + R) for MACOS and try again, make sure you have (dot) .htaccess and not just htaccess in your mysite/custom folder.

How do I site optimization php files with gzip compression using .htaccess or php.ini?

I'm using .htaccess provided by http://html5boilerplate.com/ which is correctly compressing the .html, .css, & .js files but I have not been able to get the .php files to compress unless I add <?php if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start(); ?> to the top of the page. The last thing I want to do is add that line to a hundred plus pages.
I've been using the following two sites to verify the gzip compression:
http://www.whatsmyip.org/http-compression-test/
http://www.gidnetwork.com/tools/gzip-test.php
The following suggestions have not worked either:
Gzip compression through .htaccess not working
How do you use gzip in .htaccess or php.ini?
I've also tried the following (http://perishablepress.com/fast-effective-php-compression/):
<?php // placed in a gzip_start.php file
ob_start("ob_gzhandler");
?>
<?php // placed in a gzip_stop.php file
ob_flush();
?>
# Placed in the .htaccess filew
# dual file includes for PHP compression
php_value auto_prepend_file /specify/full/path/to/gzip_start.php
php_value auto_append_file /specify/full/path/to/gzip_stop.php
Here's the Gzip section of my .htaccess file:
# ----------------------------------------------------------------------
# Gzip compression
# ----------------------------------------------------------------------
<IfModule mod_deflate.c>
# Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s,?\s(gzip|deflate)?|X{4,13}|~{4,13}|-{4,13})$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
# HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
<IfModule filter_module>
FilterDeclare COMPRESS
FilterProvider COMPRESS DEFLATE resp=Content-Type /text/(html|css|javascript|plain|x(ml|-component))/
FilterProvider COMPRESS DEFLATE resp=Content-Type /application/(javascript|json|xml|x-javascript)/
FilterChain COMPRESS
FilterProtocol COMPRESS change=yes;byteranges=no
</IfModule>
<IfModule !mod_filter.c>
# Legacy versions of Apache
AddOutputFilterByType DEFLATE text/text text/html text/plain text/css application/json
AddOutputFilterByType DEFLATE text/javascript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
</IfModule>
# Webfonts and SVG:
<FilesMatch "\.(ttf|otf|eot|svg|php)$" >
SetOutputFilter DEFLATE
</FilesMatch>
</IfModule>
Edit Your .htaccess File like This
# 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
# Or, compress certain file types by extension:
&ltfiles *.html &gt
SetOutputFilter DEFLATE
&lt/files&gt
&ltfiles *.css&gt
SetOutputFilter DEFLATE
&lt/files&gt
&ltfiles *.js &gt
SetOutputFilter DEFLATE
&lt/files&gt
&ltfiles *.img &gt
SetOutputFilter DEFLATE
&lt/files&gt
If you have views with .php extension. You will have to add this to .htaccess file
<files *.php >
SetOutputFilter DEFLATE
</files>

Categories