Concept
PHP Static is divided into: pure static and Pseudo-static, and pure static is divided into: local static and completely static
Pure static: is to save the dynamic page generated by PHP into a static HTML file, the user access to the static page, rather than the user every visit to regenerate the same page, the advantage is to reduce server overhead,
Local static: is generated in the static file, the local data or through the AJAX technology dynamically acquired;
Completely static: That is, there is no dynamic acquisition of data, so the content is from a static HTML page
Pseudo-static: In fact, dynamic access, its essence is the dynamic generation of data, you visit a URL similar to "HTTP://YOURHOST,COM/INDEX/POST/12", is a static address, the address is more in the blog address, but pseudo-static, The URL you visit is actually parsed by the server, or it resolves to an address similar to "http://yourhost,com/?c=index&a=post&id=12", so called pseudo-static
Pseudo-Static Advantages: beautiful, convenient search engine included
The implementation of pure static
Using the built-in OB function of PHP to achieve the static page, the approximate steps are as follows:
<?php Ob_start(); // ?>
<p> I am the static content to be generated, or you can generate dynamic content at that point in the link database </p>
Ob_get_clean () ); // Save the generated static content to the index.html file instead of the output to the browser
?>
Trigger system to generate a purely static page
Method: Add cache time to page; manual trigger
Page Add cache time
<?PHP$file _name= ' index.html ';if(file_exists($file _name) &&Filemtime($file _name) - Time() < 10) {//If the file is present and the last modification time is less than the set time of 10s//filemtime ($file _name);//Get File Last modified time//time ();//Current Time require_once($file _name);//Introducing Files}Else{ Ob_start( ); ?><p> I was going to generate static content </p> <?PHPfile_put_contents($file _name,ob_get_contents() )//Output to Browser}
What if the background data is finer and the timed refresh cannot change the static page in time? All features that introduce manual triggering
Manual Trigger
Manual triggering of the approximate style is similar to the Youku video comment area, when there is a new comment, will be a piece of yellow yellow small hint box: "There are new comments, click Update", also similar to the application of the decline in the refresh mechanism, to find it yourself.
In addition to the Linux crontab timed scanning program
*/5****php/data/Static/index.php
Partial static content does not narrate
PHP pseudo-static
//static: http://yourhost.com/index.php/12/2.html//dynamic: http://yourhost.com/index.php?type=12&id=2$pathinfo=$_server[' Path_info '];if(Preg_match('/^\/(\d+) \ (\d+)/',$pathinfo,$path) ){ $type=$path[1]; $id=$path[2]; Echo' Type= ',$type, ' &id= ',$id;//get type and ID for further processing}Else{ //Error Handling Echo"Err";}
Apache Server Rewrite configuration
In the httpd.conf file, locate
#注释: Remove the front "#" to open the rewrite service, restart the server to take effect
#LoadModule Rewrite_module modules/mod_rewrite.so
#注释: http-vhosts.conf file is a virtual domain name configuration file, open change file can be configured virtual domain name, usually by default is turned on
If you do not configure the virtual domain name, you can refer to my other article:wampserver configuration changes and problem summary
Rewrite pseudo-static configuration
<virtualhost *:80> ServerAdmin [email protected]-host.example. COM "c:/apache24/docs/dummy-host.example.com" ServerName dummy-host.example. COM serveralias www. dummy-host.example. com " Logs/dummy-host.example.com-error.log " " Logs/dummy-host.example.com-access.log " common #配置规则如下所示 Rewriteengine on ^/vidio/([0-9]*). html$/vidio.php?id=$1 </VirtualHost>
Rewriteengine additional configuration rules will be added later
Now when you visit http://yourhost.com/vidio/12.html, it's the equivalent of visiting http://yourhost.com/vidio.php?id=12
problem: After configuring the above content, the following problems exist? If the static page exists under the project directory, is it access to our static pages or to our pseudo-static files?
After testing we found that does not access the static page, if we want to visit our static page what to do?
Workarounds for pseudo-static and static page conflicts:
# The complete configuration rules are as follows Rewriteengine on# adds the following two items,!-d and !-f represent directories and files respectively # Access static pages Rewritecond%{document_root}%{request_filename}-D when accessing pseudo-static and corresponding static directories and file conflicts %{document_root}%{request_filename}-F ^/index/([0-9]*). html$/index.php?id=$1
PHP page static/pure static/pseudo-static