I'm trying to use gzip on my site.
I'm trying to compress, php, css and js files. The server is apache 1.3, and the code I have in the .htaccess file is:
# compress all text & html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml
But when I upload this, I just get an Error 500 page.
Any ideas.
Try this
<Files *>
#Compress
SetOutputFilter GZIP
</Files>
Or this
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript
</ifmodule>
AddOutputFilterByType doesn't appear to be available on Apache 1.3 (src). I believe you'll need to use mod_gzip instead.
"Compatibility: Available in Apache 2.0.33 and later; deprecated in Apache 2.1 and later"
Related
in my Joomla3 Website, when I enabled Gzip(from Global config , Cpanel Optimize website , .htaccess) , worked as well but just in one page(Homepage) .
Why does this happen?
php.ini
zlib.output_compression = On
zlib.output_compression_level = 9
.htaccess
<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/font
AddOutputFilterByType DEFLATE application/font-truetype
AddOutputFilterByType DEFLATE application/font-ttf
AddOutputFilterByType DEFLATE application/font-otf
AddOutputFilterByType DEFLATE application/font-opentype
AddOutputFilterByType DEFLATE application/font-woff
AddOutputFilterByType DEFLATE application/font-woff2
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/woff
AddOutputFilterByType DEFLATE font/woff2
</IfModule>
## END EXPIRES CACHING - JCH OPTIMIZE
<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>
I started to look at my security and firewall plugins. Specifically, ModSecurity – an application for Web Hosting Manager that helps prevent attacks on your web server. It is a great firewall application and a must have if you are running WHM in my opinion. Interestingly enough, I noticed that if I disabled the Rules Processing engine compression, would work WITH pretty permalinks. This led me to where the rules came from. Which happens to be Pxysoft Anti Malware, another great plugin which I plan to review later. So I went through the rules directives located in the file modsec2.antimalware.conf (where the rules came from). I started commenting out every option and rule and then toggling the rules engine on and off – one by one. I did this by connecting via SSH. Which if you’re not familiar with, you really should read in-depth tutorials before messing around. Anyways, I came across the option SecDisableBackendCompression On and commented it out. After restarting the rules engine, gzip worked on all URLs! Finally!
I have tried everything and I cannot get gzip or mod_deflate to work. I have placed almost everything into my .htaccess file as well as my apache2.conf file. They all do not work.
Here is my server configuration:
Amazon EC2 with everything forced to https://www. with Apache (apache2) and Ubuntu. Every time I run my website through an online tester, it says that my gzip is not working/enabled. I checked multiple times and my mod_deflate and my mod_filter are both installed and enabled and running.
I've also restarted my server and restarted apache a few times but it still does not recognize that my files are gzip'ed. Here's one of the multiple codes I've tried to add from gtmetrix:
<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>
I ran my website through gtmetrix and it says my .js files and my .css files are not compressed through gzip. What is wrong?
Okay, my index is a .php page so I had to add this in my index.php page:
ob_start("ob_gzhandler");
I am creating a .htaccess file that will compress my website. I copied and pasted the gzip code but when I tested the website it did not compress.
I placed my .htaccess file in the public/html directory along with other web pages, and I made sure to change the file name from the original txt file.
Here is the code from the .htaccess file
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
ErrorDocument 400 /400.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
ErrorDocument 502 /502.html
ErrorDocument 504 /504.html
AddType application/octet-stream .avi .mpg .mov .pdf .xls .mp4 .doc
# disable directory browsing
Options All -Indexes
<FilesMatch ".(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
Order Allow,Deny
Deny from all
</FilesMatch>
# 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:
<files *.html>
SetOutputFilter DEFLATE
</files>
first thing first, make sure your apache has mod_gzip or mod_deflate loaded
run this and check it
print_r(apache_get_modules());
note: for apache 2+ you need mod_deflate, for earlier versions mod_gzip (you may need to alter your htaccess file in that case)
I am having trouble with .htaccess and I am on ubuntu, the problem is, when I write an uri like this,
127.0.0.1/u
the .htaccess searches for a file and when It finds a file that starts with that letter, the uri changes directly to this,
http://127.0.0.1:8000/u/?tab_id=u
But, it should be like this,
http://127.0.0.1/u
It happens beacuse there are files that start with u like, user-edit.php and user-login.php ....
when I write
http:://127.0.0.1/a
or any uri that does not match any file, it runs perfect, this is my .htaccess code
RewriteEngine On
RewriteRule ^([//a-zçöşığüA-ZÇÖŞİĞÜ0-9_-]+)$ tab.php?tab_id=$1 [QSA,L]
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
<files *.html>
SetOutputFilter DEFLATE
</files>
I searched a lot, but cannot find the solution, thank you for any help
Sounds like a MultiViews problem. Disable this by using
Options -MultiViews
I am kind of confused with the .htaccess file. I want gzip compression and deny from all in a directory. My question is can "deny from all" be with gzip compression or it has any problems?
# 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:
<Files *.html>
SetOutputFilter DEFLATE
</Files>
deny from all
deny from all means no one can access the directory directly via a URL. Any content sent to the browser from that directory has to come via a server-side script placed elsewhere, which means that .htaccess is bypassed entirely - so the compression won't take place.
Your server-side script will therefore have to perform the compression on its own using http_deflate before outputting the data from those files.