Home >Backend Development >PHP Tutorial >PHP+.htaccess realizes GZIP compression and transmission of static HTML files in the whole site (1)_PHP tutorial
The power of apache finally exceeded my imagination. I only touched a little bit of PHP's fur like a dragonfly. This fur exploded on the basis of my original knowledge base, like the "avalanche breakdown" of the PN junction, which made me think It combines a variety of technologies with unlimited application prospects.
Since Kyushu’s future servers limit traffic, reducing the traffic load can also reduce money expenditures.
The most convenient way to reduce traffic is to use Gzip compression. The gzip compression of apache is accomplished by a class library called zlib and the gzip module (mod_gzip.c). There are a group of experts who specialize in research on this thing, because gzip itself is famous and has high compression rate open source compression principle, so our open source apache will adopt this open source compression technology.
Well, this .htaccess is also an awesome tool for apache. It is so powerful. It also depends on what modules your apache has installed to determine what you can write in this file. For example, if you have installed URL rewriting Module (Module mod_rewrite.c), you can write some URL rewriting code to implement your file rewriting.
Knowledge dissemination completed. . . .
Get to the point.
How to convert the real static html files of your whole site into gzip transmission?
For the convenience of understanding, I wrote a simple php program for everyone.
First we create a l.php using gzip compression algorithm, read xxx.html in the file and display it, and then rewrite xxx.html to 1.php in .htaccess. Keep it simple. Since our server considers .htaccess to have the highest priority, when accessing xxx.html, this static file is not accessed, but 1.php is accessed.
The following is my code: (read in index2. html, and then rewrite it)
.htaccess: