Php pseudo static reprinted from: http://www.cnblogs.com/ainiaa/archive/2010/07/25/1784564.html
I have been working on php Development. during the development process, I have long heard of the "pseudo-static" remark. But I have never understood it.
Today, I finally decided to have a good understanding of this content.
First, what is pseudo-static:
Pseudo-static URL rewriting is a dynamic URL that looks like a static one. In other words, dynamic web pages remove the parameters of dynamic web pages by rewriting the URL method, but there is no need to rewrite the pages in the actual web page Directory.
In addition, two additional terms are being added.
Static URL: pure static HTML document, which can be found by using filetype: htm
Dynamic Web site: the content is stored in the database and displayed as required? # & Display different parameters, such as: news. php? Lang = cn & class = 1 & id = 2
Benefits and disadvantages between dynamic, static, and pseudo-static (new)
Dynamic website
First, it is wrong for Google to say "cannot be crawled". Google can handle dynamic websites well and capture them smoothly; the statement "no more than three parameters" is also incorrect. Google can capture dynamic URLs with more than three parameters. however, to avoid too long URLs, we should minimize the number of parameters.
Secondly, dynamic web sites have some advantages. what is news. php mentioned above? Lang = cn & class = 1 & id = 2 as an example. the URL parameters tell Google exactly that the URL content language is cn, belongs to Category 1, Content ID is 2, it is easier for Google to recognize and process content.
Finally, the dynamic Web site should be simplified as much as possible, especially the session id (sid) and query parameters, which may cause a large number of identical pages.
Static Website
First, the absolute advantage of the static website is its clarity./product/nokia/n95.html and/about.html can be easily understood, so that the number of clicks in the search results may be relatively high.
Second, static websites may not be the best form of websites. as mentioned in the above dynamic websites, dynamic websites can tell Google some identifiable parameters, and static websites are not properly configured if the documents (for example: it is too flat to put all HTML documents under the root directory) and other factors, but it is not as informative as the reference provided by the static website for Google.
Last ,? Does Sishu think Google has its hidden meaning in this article? "Updating pages of this type of website is time-consuming, especially when the amount of information increases rapidly, because every single page must change the compilation code ." Although I am talking about websites, is there such a problem in Google?
Pseudo static website
First, the pseudo-static website cannot make the dynamic website "static". the pseudo-static website is only a rewriting of the dynamic website. Google does not regard the pseudo-static website as an HTML document.
Second, pseudo-static is desirable, but the focus should be on removing redundant parameters, standardizing URLs, and avoiding duplicate pages as much as possible.
Finally, pseudo-static data poses great potential risks. it is best to use it when you are familiar with the website system, website structure, content distribution, and parameter meanings.
When writing pseudo-static rules, you should keep valuable parameters. do not streamline all valuable parameters, such as news. php in the previous example? Lang = cn & class = 1 & id = 2 it is best to rewrite to news-cn-class1-id2.html instead of oversimplified to news-2.html.
Then, the pseudo-static file must not contain the session id (sid) and query parameters,/product. asp? Sid = 98971298178906 & id = 1234, where the sid can be recognized and blocked by Google, but if it is rewritten as/product/98971298178906/1234, Google will not be able to recognize it, there are still infinite duplicate pages on the entire site (each session generates a new session ID ).
We should choose pseudo static or real static
1. there is no difference between real static and false static for SEO.
2. using true or static data may damage the hard disk and affect the Forum performance.
3. using pseudo-static data will occupy a certain amount of CPU usage, and a large amount of use will overload the CPU.
4. the most important thing is that we need static resources for SEO.
Therefore:
1. you can use the true or static method to eliminate it directly, because no matter how it is generated, it is very bad for the hard disk.
2. since the authenticity and static effect are the same, we can choose pseudo static.
3. However, excessive use of pseudo-static resources will overload the CPU.
4. as long as we do not need to use it in large quantities.
5. since static content is just for SEO, we only need to give it to SEO through pseudo static content and do not need it for users.
6. Therefore, we only need to use pseudo static data in the Archiver dedicated to SEO crawling.
7. thank you for your patience in reading my article.
8. What are you puzzled about or have different opinions?
Comments on pseudo-static and real-static
Real static and pseudo static are essentially different. For browser users to process a pure html and a php that calls multiple data, the CPU usage is obviously less. I remember someone who said that html hard drives were frequently downloaded and read/written. He said that it seems that the database does not need to be read or written to the disk. Besides, there are a lot of scattered php Cache files on the hard disk, do these reads require no disk operations? Ridiculous.
You can achieve this by reading a single html + image Flash and other attachments, why do I have to read the database, read the php Cache file, re-integrate the data output, and add attachments such as image Flash? The CMS homepage does not require a lot of interaction. the forum should not be used here. On the contrary, you should consider more: beautiful! Compatible! Intuitive information! Performance! Stability!
The following describes how to convert a php pseudo-static statement:
1 2 // pseudo-static method 1
3
4 // localhost/php100/test. php? Id | 1 @ action | 2
5 $ Php2Html_FileUrl = $ _ SERVER ["REQUEST_URI"];
6 echo $ Php2Html_FileUrl ."
"; // Php100/test. php? Id | 1 @ action | 2
7 $ Php2Html_UrlString = str_replace ("? "," ", Str_replace ("/"," ", strrchr ($ Php2Html_FileUrl ,"/"),"? ")));
8 echo $ Php2Html_UrlString ."
"; // Id | 1 @ action | 2
9 $ Php2Html_UrlQueryStrList = explode ("@", $ Php2Html_UrlString );
10 print_r ($ Php2Html_UrlQueryStrList); // Array ([0] => id | 1 [1] => action | 2)
11 echo"
";
12 foreach ($ Php2Html_UrlQueryStrList as $ Php2Html_UrlQueryStr)
13 {
14 $ Php2Html_TmpArray = explode ("|", $ Php2Html_UrlQueryStr );
15 print_r ($ Php2Html_TmpArray); // Array ([0] => id [1] => 1); Array ([0] => action [1] => 2)
16 echo"
";
17 $ _ GET [$ Php2Html_TmpArray [0] = $ Php2Html_TmpArray [1];
18}
19 // echo 'false static: $ _ GET variable
';
20 print_r ($ _ GET); // Array ([id | 1 @ action | 2] => [id] => 1 [action] => 2)
21 echo"
";
22 echo "";
23 echo $ _ GET [id]."
"; // 1
24 echo $ _ GET [action]; // 2
25?>
26
1 2 // pseudo-static method 2
3
4 // localhost/php100/test. php/1/2
5 $ filename = basename ($ _ SERVER ['script_name']);
6 echo $ _ SERVER ['script_name']."
"; // Php100/test. php
7 echo $ filename ."
"; // Test. php
8
9 if (strtolower ($ filename) = 'Test. php '){
10 if (! Empty ($ _ GET [id]) {
11 $ id = intval ($ _ GET [id]);
12 echo $ id ."
";
13 $ action = intval ($ _ GET [action]);
14 echo $ action ."
";
15} else {
16 $ nav = $ _ SERVER ['request_uri '];
17 echo "1:". $ nav ."
"; // Php100/test. php/1/2
18 $ script = $ _ SERVER ['script_name'];
19 echo "2:". $ script ."
"; // Php100/test. php
20 $ nav = ereg_replace ("^ $ script", "", urldecode ($ nav ));
21 echo $ nav ."
"; // 1/2
22 $ vars = explode ("/", $ nav );
23 print_r ($ vars); // Array ([0] => [1] => 1 [2] => 2)
24 echo"
";
25 $ id = intval ($ vars [1]);
26 $ action = intval ($ vars [2]);
27}
28 echo $ id. '&'. $ action;
29}
30?>
31
1 2 // pseudo-static method 3
3
4
5 function mod_rewrite (){
6 global $ _ GET;
7 $ nav = $ _ SERVER ["REQUEST_URI"];
8 echo $ nav ."
";
9 $ script_name = $ _ SERVER ["SCRIPT_NAME"];
10 echo $ script_name ."
";
11 $ nav = substr (ereg_replace ("^ $ script_name", "", urldecode ($ nav), 1 );
12 echo $ nav ."
";
13 $ nav = preg_replace ("/^. ht (m) {1} (l) {0, 1} $/", "", $ nav); // The end of the sentence is .htmlor .htm.
14 echo $ nav ."
";
15 $ vars = explode ("/", $ nav );
16 print_r ($ vars );
17 echo"
";
18 for ($ I = 0; $ I <Count ($ vars); $ I ++ = 2 ){
19 $ _ GET ["$ vars [$ I]"] = $ vars [$ I + 1];
20}
21 return $ _ GET;
22}
23 mod_rewrite ();
24 $ year = $ _ GET ["year"]; // The result is 2006'
25 echo $ year ."
";
26 $ action = $ _ GET ["action"]; // The result is '_ add'
27 echo $ action;
28?>
29
1 2 // pseudo-static method 4
3
4 // 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.
5 if (@ $ path_info = $ _ SERVER ["PATH_INFO"]) {
6 // regular expression matching parameters
7 if (preg_match ("// (\ d +), (\ d +), (\ d + )\. html/si ", $ path_info, $ arr_path )){
8 $ gid = intval ($ arr_path [1]); // get the value 1
9 $ sid = intval ($ arr_path [2]); // get the value 100
10 $ softid = intval ($ arr_path [3]); // get the value 8630
11} else die ("Path: Error! ");
12 // equivalent to soft. php? Gid = 1 & sid = 100 & softid = 8630
13} else die ('path: Nothing! ');
14?>
15
If you do not want to use php to implement pseudo-static state, you can use the url rewrite function provided by apache, nginx, iis, and other servers to set it.
References:
Http://baike.baidu.com/view/1570373.htm? Fr = ala0_1 #2
Http://blog.sina.com.cn/s/blog_4a657b6b0100gdnk.html
Http://www.chinaz.com/Webbiz/Exp/01041029142010.html
Http://apps.hi.baidu.com/share/detail/5308118