Apache's power finally beyond my imagination, just Dragonfly water touch a little php fur, this fur on the basis of my original knowledge base exploded, as if the PN knot "avalanche breakdown", let me think of a variety of technologies combined with unlimited application prospects.
As Kyushu's future servers limit traffic, reducing the traffic load can also reduce the cost of money.
How to reduce traffic, the most convenient way is to use gzip compression, this Apache gzip compression is a class library called Zlib and gzip module (MOD_GZIP.C) done, this thing specifically a bunch of cattle people study, because Gzip itself is famous, And with a high compression rate of open source compression principle, so our open-source Apache will adopt this open-source compression technology.
Well, this. Htaccess is also an Apache bull than something, too powerful, but also according to your Apache installed what module to decide what you can write in this file, for example, you installed a URL rewrite module mod_ REWRITE.C) Then you can write some URL rewrite code to implement your file rewrite.
Knowledge popularization is complete ....
Go to the chase.
How to make your own full station of the real static HTML file, into the gzip transfer it?
For ease of understanding, I wrote a simple PHP program for everyone.
First we create a l.php using the gzip compression algorithm, read the xxx.html in the file and display it, and then rewrite xxx.html to 1.php in the. htaccess. It's simple. Since our server believes that the. Htaccess has the highest priority, it accesses the xxx.html without accessing the static file, instead accessing the 1.php.
Here's My Code: (read in index2.html and rewrite it)
. htaccess:
Copy CodeThe code is as follows:
# Open the Rewriteengine mode
Rewriteengine on
Rewritebase/
Rewriterule index2\.html l.php?fn=index2.html
1.php
Copy CodeThe code is as follows:
$phpver = Phpversion ();
$useragent = (Isset ($_server["Http_user_agent"))? $_server["Http_user_agent"]: $HTTP _user_agent;
if ($phpver >= ' 4.0.4pl1 ' && (strstr ($useragent, ' compatible ') | | strstr ($useragent, ' Gecko ')))
{
if (extension_loaded (' zlib '))
{
Ob_start (' Ob_gzhandler ');
}
}
else if ($phpver > ' 4.0 ')
{
if (strstr ($HTTP _server_vars[' http_accept_encoding '), ' gzip '))
{
if (extension_loaded (' zlib '))
{
$do _gzip_compress = TRUE;
Ob_start ();
Ob_implicit_flush (0);
Header (' Content-encoding:gzip ');
}
}
}
?>
$rfile = Addslashes (dirname (dirname (__file__)). ' /'.'. /httpdocs/'. $_request[' FN ';
echo read_file_contents ($rfile);
function Read_file_contents ($file)
{
if (!function_exists ("file_get_contents")) return file_get_contents ($file);
$ifile = fopen ($file, "R");
$contents = false;
if ($ifile) while (!feof ($ifile)) $contents. = Fgets ($ifile);
Fclose ($ifile);
return $contents;
}
?>
Compress buffered output if required and send to browser
if ($do _gzip_compress)
{
//
Borrowed from php.net!
//
$gzip _contents = ob_get_contents ();
Ob_end_clean ();
$gzip _size = strlen ($gzip _contents);
$gzip _CRC = CRC32 ($gzip _contents);
$gzip _contents = gzcompress ($gzip _contents, 9);
$gzip _contents = substr ($gzip _contents, 0, strlen ($gzip _contents)-4);
echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
echo $gzip _contents;
Echo Pack (' V ', $gzip _CRC);
Echo Pack (' V ', $gzip _size);
}
Exit
?>
Actually, this thing can be solved in a better way.
Rewritecond%{request_filename}!-f
Rewritecond%{request_filename}!-d
Rewriterule. /xxx/xxx.php [L]
But I have not studied how to deal with this%{request_filename}, but also look at the master enlighten.
http://www.bkjia.com/PHPjc/317907.html www.bkjia.com true http://www.bkjia.com/PHPjc/317907.html techarticle Apache's power finally beyond my imagination, just Dragonfly water touch a little php fur, this fur on the basis of my original knowledge base exploded, as if the PN knot "avalanche breakdown ...