PHP pseudo-static writing-its pseudo-static name is also known as: URL rewriting is mainly generated for SEO. (What is SEO? You don't have to ask me this. Haha ~ If you do not understand SEO, then ~~~~) Method 1: for example, the webpage http://www.2cto.com/soft.php/1,100,8630.html ..syntaxhigh
PHP pseudo-static writing-one
Pseudo static name: URL rewriting
Mainly for SEO. (What is SEO? You don't have to ask me this. Haha ~ If you do not understand SEO, then ~~~~)
Method 1:
For example, this webpage
Http://www.2cto.com/soft. php/1,100,8630.html
In fact, the soft. php parameter is 1,100,863 0.
Equivalent to soft. php? A = 1 & B = 1 = 100 & c = 8630, but such a URL is too hard to remember. Search engines do not like it either.
Real static only completely generates HTML.
Output directly when accessing the client. No script explanation is required. When the traffic is very large (for example, when there are millions of visits each day), it will play a very good effect. That is to say, the server actually has this HTML page.
Of course, when the traffic on your website is not that large. URL rewriting is the best method (in my opinion, server load balancer can be considered when the traffic is high. It also does not matter)
There are many URL rewriting methods, such as APACHE and IISREWRITE. Even PHP scripts can be processed directly. For example, in the above example, PHP scripts are directly processed (the advantage of this method is to directly reduce the pressure on the WEB server when the traffic is high. PS: Also personal opinion:
========================================================== ==========
The following uses a program as an example to describe the PHP pseudo-static program implementation method. In fact, this method has already been released in other forums.
Program example:
Http://www.2cto.com/soft. php/1,100,8630.html
CODE:
// Use the server variable to obtain the PATH_INFO information. In this example, it is/, 8630.html, that is, the part after the execution script name.
If (@ $ path_info = $ _ SERVER ["PATH_INFO"]) {
// Regular expression matching parameters
If (preg_match ("// (\ d +), (\ d +), (\ d +) \. html/si", $ path_info, $ arr_path )){
$ Gid = intval ($ arr_path [1]); // get the value 1
$ Sid = intval ($ arr_path [2]); // get the value 100
$ Softid = intval ($ arr_path [3]); // get the value 8630
} Else die ("Path: Error! ");
// Equivalent to soft. php? Gid = 1 & sid = 100 & softid = 8630
// It's that simple .~)
Method 2:
1. open the configuration file httpd. conf of Apache.
2. remove the # LoadModule rewrite_module modules/mod_rewrite before #.
3. add the following in httpd. conf:
RewriteEngine On
# RewriteCond % {ENV: SCRIPT_URL }(? : Index | dispbbs00000000-0-900000000.html
RewriteRule ^ (.*? (? : Index | dispbbs00000000-(-0-9000000000000.html 1.php? _ Is_apache_rewrite = 1 & __ rewrite_arg = 2
4. to map asp post URLs to php posts And Between:
RewriteMap tolowercase int: tolower
RewriteCond % {QUERY_STRING }(? : Boardid | page | id | replyid | star | skin) = d + [NC]
RewriteRule ^ (.*(? : Index | dispbbs). asp 1.php? {Tolowercase: % {QUERY_STRING }}&__ is_apache_rewrite = 1
5. save httpd. conf and restart Apache
Method 3:
/*
Function: PHP pseudo-static page implementation
Usage:
For example, the link is test. php/year/2006/action/_add.html.
Mod_rewrite ();
$ Yearn = $ _ GET ["year"]; // The result is 2006'
$ Action = $ _ GET ["action"]; // The result is '_ add'
*/
Function mod_rewrite (){
Global $ _ GET;
$ Nav = $ _ SERVER ["REQUEST_URI"];
$ Script_name = $ _ SERVER ["SCRIPT_NAME"];
$ Nav = substr (ereg_replace ("^ $ script_name", "", urldecode ($ nav), 1 );
$ Nav = preg_replace ("/^. ht (m) {1} (l) {0, 1} $/", "", $ nav); // The end of this sentence is .htmlor .htm.
$ Vars = explode ("/", $ nav );
For ($ I = 0; $ I $ _ GET ["$ vars [$ I]"] = $ vars [$ I + 1];
}
Return $ _ GET;
}
Mod_rewrite ();
$ Yearn = $ _ GET ["year"]; // The result is 2006'
$ Action = $ _ GET ["action"]; // The result is '_ add'
Echo $ yearn;
Echo $ action;
?>
/*
Function: PHP pseudo-static page implementation
Usage:
For example, the link is test. php/year/2006/action/_add.html.
Mod_rewrite ();
$ Yearn = $ _ GET ["year"]; // The result is 2006'
$ Action = $ _ GET ["action"]; // The result is '_ add'
*/
Function mod_rewrite (){
Global $ _ GET;
$ Nav = $ _ SERVER ["REQUEST_URI"];
$ Script_name = $ _ SERVER ["SCRIPT_NAME"];
$ Nav = substr (ereg_replace ("^ $ script_name", "", urldecode ($ nav), 1 );
$ Nav = preg_replace ("/^. ht (m) {1} (l) {0, 1} $/", "", $ nav); // The end of this sentence is .htmlor .htm.
$ Vars = explode ("/", $ nav );
For ($ I = 0; $ I $ _ GET ["$ vars [$ I]"] = $ vars [$ I + 1];
}
Return $ _ GET;
}
Mod_rewrite ();
$ Yearn = $ _ GET ["year"]; // The result is 2006'
$ Action = $ _ GET ["action"]; // The result is '_ add'
Echo $ yearn;
Echo $ action;
?>
This method is the most direct !~~~ Haha... the water and wood for you to provide...