PHP implements URL static. Php Tutorial real-time url phpphp real-time pseudo-static another type of pseudo-static formula, that is, the user and the search engine see the static page with the suffix of .html, but in fact it is still a dynamic program, php Tutorial implements url static
Php implements pseudo-static
There is another pseudo-static formula, that is, the user and the search engine see the static page with the suffix of .html, but in fact it is still a dynamic program, but it is disguised in some way.
There are two ways to achieve this:
The first method is to implement static link through url rewrite on the web server. the following uses apache as an example to describe the implementation method. For users with server configuration permissions, we recommend that you use the mod_rewrite module of apache. we assume that the mod_rewrite module has been installed. Open the apache configuration file, find the corresponding host, and add the following code:
Rewriteengine on
Rewriterule ^/abc/([a-z] +)/(%0-9%%%%%.html $/abc. php? Action = $1 & id = $2
Then execute service httpd reload in shell, and let apache reload the configuration.
But for most of us, we only purchase space and have no permission to modify the apache configuration file. Is there any way to change the configuration file? No, of course, there is a way to first enter the root directory of our space (such as public_html), and then create a file named. htaccess. The content of this file is basically as follows:
Rewriteengine on
Rewritebase/
Rewriterule ^ post/(%0-9%%%%.htm read. php? 1
Rewriterule ^ post/(%0-9%%%%%_(%0-9%%%%%.htm read. php? 1 & page = 2
Rewriterule ^ post/(%0-9%%%%%_(%0-9%%%%%%%%%%_(%0-9%%%%%.htm read. php? 1 & page = 2 & = 3
Php program writing
Function mod_rewrite (){
If (isset ($ _ server ['path_info']) {
$ Url = substr ($ _ server ['path_info'], 1 );
$ Url = explode ('/', $ url );
Foreach ($ url as $ key => $ value ){
If ($ key % 2! = 1 ){
If ($ value! = '') $ _ Get [$ value] = $ url [$ key + 1];
$ Querystring [] = $ value. '='. $ url [$ key + 1];
}
}
$ _ Server ['query_string '] = implode ("&", $ querystring );
$ _ Server ['php_self '] = substr ($ _ server ['php_self']
, 0, strpos ($ _ server ['php_self '],'. php') + 4 );
$ _ Server ['request_uri '] = $ _ server ['php_self']
.'? '. $ _ Server ['query_string'];
}
}
Php implements pseudo-static, and there is another pseudo-static formula, that is, the user and the search engine see the static page with the suffix of .html, but in fact it is still a dynamic program ,...