How do you use gzip in .htaccess or php.ini?

2019-08-03 23:07发布

问题:

I'm looking for a simple one line code that will use gzip to compress css, html, js, and php files on the web server. How can I do this with the .htaccess file or php.ini file? (My css and js files are in seperate folders in the root directory)

回答1:

You're most likely looking for mod_deflate module in Apache. Enable it in your httpd.conf and also enable .htaccess then add this code in your .htaccess under DOCUMENT_ROOT:

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


回答2:

<Files *>
    #Compress
    SetOutputFilter GZIP
</Files>