PHP pseudo-static

Source: Internet
Author: User
Tags explode vars

First, what is pseudo-static:

Pseudo-static aka URL rewrite, is a dynamic URL that looks like a static URL. In other words, dynamic Web pages are implemented to remove the parameters of a dynamic Web page by overriding the URL method, but there is no need to implement a rewritten page in the actual Web page directory.

In addition, two noun resolutions are added

Static URLs: pure static HTML documents, Web pages that can be queried using filetype:htm

Dynamic URLs: Content is stored in the database, according to the requirements of the content, URL in the? # & Show different parameters, such as: news.php? lang=cn&class=1&id=2

Advantages and disadvantages of dynamic, static and pseudo-static (new)

Dynamic URLs

First of all, the dynamic URL for Google, "can not be crawled" is wrong, Google can handle dynamic URLs and smooth crawl, followed by "parameters can not exceed 3" is not correct, Google can crawl parameters more than 3 dynamic URLs, however, To avoid URLs that are too long, you should minimize the parameters.

Secondly, the dynamic URL has its certain advantages, to the above mentioned news.php? lang=cn&class=1&id=2, for example, the URL of the parameters accurately tell Google, this URL content language is CN, is classified as Category 1, Content ID 2, more convenient for Google to identify the content processing.

Finally, the dynamic URLs should be as concise as possible, especially the session ID (SID) and query parameters, which can easily cause a large number of identical pages.

Static URLs

First of all, the absolute advantage of static URLs is its clarity,/product/nokia/n95.html and/about.html can be easily understood, resulting in a relatively high number of hits in search results.

Second, the static URL is not necessarily the best form of the Web site, the dynamic URL said that dynamic URLs can tell Google some of the parameters can be identified, and static URLs if the document is not properly arranged (such as: too flat, the HTML document is placed in the root directory) and other factors, Rather than static URLs for Google to provide a rich reference information.

Finally, does it feel like Google has a hidden meaning in this article? "Updating pages of this type of URLs can be time-consuming, especially if the amount of information is growing fast because each individual page has to change the compiled code." "It's a website, but is there such a problem in Google's system?" he said.

Pseudo static URLs

First, pseudo-static URLs can not make dynamic URLs "static", pseudo-static is only a rewrite of dynamic URLs, Google does not think pseudo-static is an HTML document.

Second, pseudo-static preferable, but should focus on the removal of redundant parameters, canonical URLs, as far as possible to avoid repeating the page.

Finally, pseudo-static has great potential danger, preferably in the site system, website structure, content distribution, parameter meaning familiar with the case of the use.

When writing pseudo-static rules, you should retain valuable parameters and not all the valuable parameters, such as the news.php in the previous example? Lang=cn&class=1&id=2 is best rewritten as news-cn-class1-id2.html, rather than as an excessive refinement rewrite for news-2.html.

And then the pseudo-static must not contain the session ID (SID) and query parameters,/product.asp? sid=98971298178906&id=1234 such a dynamic URL, where the SID would have been recognized and blocked by Google, but if rewritten as/product/98971298178906/1234,google not only unrecognized, It also creates an infinite number of duplicate pages in the entire station (each session will produce a new session ID).

Should we choose pseudo-static or true-static?

1, the use of true static and false static for SEO no difference

2, the use of true static may cause hard disk damage and will affect the performance of the Forum

3, use pseudo-static will occupy a certain amount of CPU share, large use will lead to CPU overload

4, the most important point, we want to static is to SEO

So:

1, the use of true static method can be directly excluded, because no matter how the generation, the hard disk is very hurt.

2, since the authenticity of the static effect of the same, we can choose Pseudo-static.

3, but pseudo-static heavy use will cause CPU overload.

4, so we just do not use a lot of it.

5, since the static just to look at the SEO, we only need pseudo-static to SEO on the line, do not need to give users the use.

6, so we only in the special offer to SEO crawl archiver use pseudo-static on it.

7, thank you for your patience to read the article I wrote.

8, what do not understand the place or have different views welcomed the proposed

Comments on pseudo-static and true-static

The real static and pseudo-static still have the essential difference. In order to browse the user processing a pure HTML and a call to multiple data PHP in the CPU usage significantly less. I remember someone said that HTML download hard disk read and write frequently, he said that it seems to read the database without read and write disk, let alone a lot of cache of scattered PHP is also placed on the hard disk, these read without disk operation? Ridiculous.

Read a single html+ image flash and other accessories can be achieved, why bother to read the database and read the PHP cache file and re-integration of data output and other accessories such as flash pictures so much trouble? CMS home does not need a lot of interaction, forum that set should not get here to use, on the contrary should be more consideration is: beautiful! Compatible! The intuitive information! Performance! There's stability!

In turn a PHP pseudo-static implementation four method:

1 <?php
2//pseudo-static method one
3
4//localhost/php100/test.php?id| [Email protected]|2
5 $Php 2html_fileurl = $_server["Request_uri"];
6 echo $Php 2html_fileurl. " <br> ";///php100/test.php?id| [Email protected]|2
7 $Php 2html_urlstring = Str_replace ("?", "" ", Str_replace ("/"," ", STRRCHR (STRRCHR ($Php 2html_fileurl,"/"),"? "));
8 echo $Php 2html_urlstring. " <br> ";//id| [Email protected]|2
9 $Php 2html_urlquerystrlist = explode ("@", $Php 2html_urlstring);
Print_r ($Php 2html_urlquerystrlist);//Array ([0] = id|1 [1] = action|2)
echo "<br>";
($Php 2html_urlquerystrlist as $Php 2html_urlquerystr)
13 {
$PHP 2html_tmparray = explode ("|", $Php 2HTML_URLQUERYSTR);
Print_r ($Php 2html_tmparray);//Array ([0] = id [1] = 1); Array ([0] = = action [1] = 2)
echo "<br>";
$_get[$Php 2html_tmparray[0]] = $Php 2html_tmparray[1];
18}
//echo ' false static: $_get variable <br/> ';
Print_r ($_get); Array ([id|[ email protected]|2] = [ID] + 1 [action] + 2)
echo "<br>";
echo "Echo $_get[id]. " <br> ";//1
Echo $_get[action];//2
?>
26

1 <?php
2//pseudo-static method two
3
4//LOCALHOST/PHP100/TEST.PHP/1/2
5 $filename = basename ($_server[' script_name ');
6 echo $_server[' Script_name ']. " <br> ";///php100/test.php
7 echo $filename. " <br> ";//test.php
8
9 if (strtolower ($filename) = = ' test.php ') {
if (!empty ($_get[id])) {
$id =intval ($_get[id]);
echo $id. " <br> ";
$action =intval ($_get[action]);
echo $action. " <br> ";
}else{
$nav =$_server[' Request_uri '];
echo "1:" $nav. " <br> ";///PHP100/TEST.PHP/1/2
$script =$_server[' Script_name '];
echo "2:" $script. " <br> ";///php100/test.php
$nav =ereg_replace ("^ $script", "", UrlDecode ($nav));
echo $nav. " <br> "; /1/2
$vars =explode ("/", $nav);
Print_r ($vars);//Array ([0] = [1] = 1 [2] = 2)
echo "<br>";
$id =intval ($vars [1]);
=intval $action ($vars [2]);
27}
echo $id. ' & '. $action;
29}
?>
31

1 <?php
2//pseudo-static method three
3
4
5 function mod_rewrite () {
6 Global $_get;
7 $nav =$_server["Request_uri"];
8 echo $nav. " <br> ";
9 $script _name=$_server["Script_name"];
echo $script _name. " <br> ";
One $nav =substr (ereg_replace ("^ $script _name", "", UrlDecode ($nav)), 1);
echo $nav. " <br> ";
$nav =preg_replace ("/^.ht (m) {1} (l) {0,1}$/", "", $nav);//This sentence is removed from the tail. html or. htm
echo $nav. " <br> ";
$vars = Explode ("/", $nav);
Print_r ($vars);
echo "<br>";
for ($i =0; $i <count ($vars); $i +=2) {
$_get["$vars [$i]"]= $vars [$i +1];
20}
return $_get;
22}
Mod_rewrite ();
$year =$_get["Year"];//results for ' 2006 '
echo $year. " <br> ";
$action =$_get["Action"];//results for ' _add '
Echo $action;
?>
29

1 <?php
2//pseudo-static method four
3
4//Use the server variable to get path_info information in this case,/1,100,8630.html is the part that executes the script name.
5 if (@ $path _info =$_server["Path_info"]) {
6//Regular match parameters
7 if (Preg_match ("/\/(\d+), (\d+), (\d+) \.html/si", $path _info, $arr _path)) {
8 $gid =intval ($arr _path[1]); Get value 1
9 $sid =intval ($arr _path[2]); Get Value 100
$softid =intval ($arr _path[3]); Get Value 8630
One by one}else die ("path:error!");
12//equivalent to soft.php?gid=1&sid=100&softid=8630
}else die (' path:nothing! ');
?>
15

If you do not want to use PHP to implement pseudo-static, but use the Apache,nginx,iis and other server's own URL rewrite function to set.

Resources:

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

PHP pseudo-static

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.